<?php
session_start();
header('Access-Control-Allow-Origin:*');
header('Content-Type; application/json; charset=utf-8');
header('Access-control-Allow-Method: POST');
header('Access-control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-request-With');
include('db.php');
    $inputdata = json_decode(file_get_contents("php://input"), true);

    $username = $inputdata['username'];
    $password = $inputdata['password'];

    $count="";

    //verifier si le email existe avant conexion
    $verif_email=$db->prepare('SELECT * FROM tbl_user WHERE username=? AND password=?');
    $verif_email->execute(array($username, $password));
    $count = $verif_email->rowCount();
    $user = $verif_email->fetchObject();
    $var_data = (object) $user;

    if ($count == 0) {
      // mot de passe ou nom d'utilisateur incorrect
        echo(json_encode(['errorlogin' => 1]));

    } else {
        // connexion success
            echo(json_encode(['loginData' => $user]));
        
    }



    
    

