donnafirman

Untitled

Jul 1st, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. <?php
  2. header('Access-Control-Allow-Origin: *');
  3. header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
  4. header('Access-Control-Allow-Headers: Origin, Content-Type, X-Auth-Token');
  5.  
  6. $db = new PDO("mysql:host=localhost;dbname=u8237613_taxi;","u8237613_taxi","taxi123");
  7.  
  8. $data = json_decode(file_get_contents("php://input"));
  9. $password = sha1($data->password);
  10. $username = $data->username;
  11.  
  12. $userInfo = $db->query("SELECT email FROM users WHERE email='$username' AND password='$password'");
  13. $userInfo = $userInfo->fetchAll();
  14.  
  15.  
  16.  
  17. $token;
  18. if (count($userInfo) == 1){
  19. //This means that the user is logged in and let's givem a token :D :D :D
  20. $token = $username . " | " . uniqid() . uniqid() . uniqid();
  21.  
  22. $q = "UPDATE users SET token=:token WHERE email=:email AND password=:password";
  23. $query = $db->prepare($q);
  24. $execute = $query->execute(array(
  25. ":token" => $token,
  26. ":email" => $username,
  27. ":password" => $password
  28. ));
  29.  
  30. echo json_encode($userInfo);
  31.  
  32. ?>
Add Comment
Please, Sign In to add comment