Advertisement
Guest User

Untitled

a guest
Apr 10th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $user="root";
  4. $pass="";
  5. $host="localhost";
  6. $dbnamne="near_deal27";
  7. $username = $_REQUEST['username'];
  8. $password = $_REQUEST['password'];
  9.  
  10. // buat contoh
  11. // $username = 'punyasaya';
  12. // $password = 'abcd123';
  13.  
  14.  
  15. //create connection
  16. $conn = new mysqli($host, $user, $pass, $dbnamne);
  17. //check connection
  18. if($conn->connect_error){
  19. die("connection failed" .$com->connect_error);
  20. }
  21. $sql = "SELECT * FROM user WHERE username='{$username}' AND password='{$password}' LIMIT 1";
  22. $result = $conn->query($sql);
  23. $user = array();
  24. while($row =$result->fetch_assoc()){
  25. $user = $row;
  26. }
  27. if(!empty($user)) {
  28. // $_SESSION['user_id'] = $user['id'];
  29.  
  30. //generate token
  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. ), JSON_NUMERIC_CHECK);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement