taufiqhidayah97

login

Sep 12th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.39 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * @author Ravi Tamada
  5.  * @link http://www.androidhive.info/2012/01/android-login-and-registration-with-php-mysql-and-sqlite/ Complete tutorial
  6.  */
  7.  
  8. require_once 'include/DB_Functions.php';
  9. $db = new DB_Functions();
  10.  
  11. // json response array
  12. $response = array("error" => FALSE);
  13.  
  14. if (isset($_POST['email']) && isset($_POST['password'])) {
  15.  
  16.     // receiving the post params
  17.     $email = $_POST['email'];
  18.     $password = $_POST['password'];
  19.  
  20.     // get the user by email and password
  21.     $user = $db->getUserByEmailAndPassword($email, $password);
  22.  
  23.     if ($user != false) {
  24.         // use is found
  25.         $response["error"] = FALSE;
  26.         $response["uid"] = $user["unique_id"];
  27.         $response["user"]["name"] = $user["name"];
  28.         $response["user"]["email"] = $user["email"];
  29.         $response["user"]["created_at"] = $user["created_at"];
  30.         $response["user"]["updated_at"] = $user["updated_at"];
  31.         echo json_encode($response);
  32.     } else {
  33.         // user is not found with the credentials
  34.         $response["error"] = TRUE;
  35.         $response["error_msg"] = "Login credentials are wrong. Please try again!";
  36.         echo json_encode($response);
  37.     }
  38. } else {
  39.     // required post params is missing
  40.     $response["error"] = TRUE;
  41.     $response["error_msg"] = "Required parameters email or password is missing!";
  42.     echo json_encode($response);
  43. }
  44. ?>
Add Comment
Please, Sign In to add comment