<?php
ini_set('display_errors', 'On');
error_reporting(E_ERROR);


/*The following code will check for timestamp  using email in  table */
// array for JSON response (default to failure)
$response = array();
$response["success"] = 0;
$response["message"] = "Failed";

//get json string
$json = file_get_contents('php://input');

//get json array
$jsonArr = json_decode($json, true);

// check for required fields
if ( isset($jsonArr['email1']) && isset($jsonArr['time_stamp'])) { 
    
     // include db config class
     require_once __DIR__ . '/db_config.php';
     // connecting to db
     $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
     mysqli_set_charset($mysqli, "utf8");

     $email=$jsonArr['email1'];
     $timestamp=$jsonArr['time_stamp'];
     
        $stmt = $mysqli->prepare("SELECT TIMESTAMP FROM USER_ID WHERE EMAIL = ?");
        $stmt->bind_param("s", $email);
        $stmt->execute(); 
        $stmt->bind_result($times);
            while($stmt->fetch()){
                if($times > $timestamp)
                    {
                        $response["success"] = 1;
                        $response["message"] = "Success";
                        // echoing JSON response
                        echo json_encode($response);
                    }
                else if($times < $timestamp)
                    {
                        $response["success"] = 0;
                        $response["message"] = "Failed";
                        // echoing JSON response
                        echo json_encode($response);
                    }

                }    
    mysqli_close($mysqli);
 }                         
 
else{
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";
 
    // echoing JSON response
    echo json_encode($response);
}
     


?>