function verifyLogin() { $email = $_POST["email"]; $password = $_POST["password"]; $checked = $_POST["remember"]; // Check the info in the database $result = loginAction($email, $password); if ($result["statusTxt"] == "SUCCESS") { // Starting the session session_start(); $_SESSION["email"] = $email; $_SESSION["fName"] = $result["data"]["fName"]; $_SESSION["lName"] = $result["data"]["lName"]; // Setting the cookies if ($checked == "true") { setcookie("emailCookie", $email, time() + 3600 * 24 * 30); setcookie("passwordCookie", $password, time() + 3600 * 24 * 30); } // Retun data to the front-end $finalResponse = array("firstName" => $result["data"]["fName"], "lastName" => $result["data"]["lName"]); echo json_encode($finalResponse); } else { header('HTTP/1.1 406, User not found'); die(json_encode($result)); } }
<?php header('Content-type: application/json'); require_once __DIR__ . '/dataLayer.php'; $action = $_POST['action']; switch ($action) { case 'LOGIN': loginAction(); break; case 'COOKIES': verifyCookies(); break; case 'REGISTER': registerAction(); break; case 'FRIENDS': getFriends(); break; case 'ADDFRIEND': addFriend(); break; case 'USERS': getUsers(); break; case 'PROFILE': getProfile(); break; case 'ENDSESS': endSession(); break; case 'SAVET':