Guest User

Untitled

a guest
Dec 28th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $user="root";
  4. $pass="";
  5. $host="localhost";
  6. $dbnamne="neardeal";
  7.  
  8. $username = $_REQUEST['username'];
  9. $password = $_REQUEST['password'];
  10.  
  11. //create connection
  12. $conn = new mysqli($host, $user, $pass, $dbnamne);
  13.  
  14. //check connection
  15. if($conn->connect_error){
  16. die("connection failed" .$com->connect_error);
  17. }
  18.  
  19. $sql = "SELECT * FROM user WHERE username='{$username}' AND password='{$password}' LIMIT 1";
  20.  
  21. $result = $conn->query($sql);
  22. $user = array();
  23.  
  24. while($row =$result->fetch_assoc()){
  25. $user = $row;
  26. }
  27.  
  28. if(!empty($user)) {
  29. $_SESSION['user_id'] = $user['id'];
  30.  
  31. echo json_encode(array(
  32. 'success' => true,
  33. 'user' => $user
  34. ));
  35. }
  36. else {
  37. echo json_encode(array(
  38. 'success' => false,
  39. /** return empty user to prevent error when java converting to user object*/
  40. 'user' => array(
  41. 'id'=>0,
  42. 'username'=>'',
  43. 'password'=>''
  44. )
  45. ));
  46. }
Add Comment
Please, Sign In to add comment