Guest User

Untitled

a guest
Jan 25th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2. header("Access-Control-Allow-Origin: *");
  3. header("Content-Type: application/json; charset=UTF-8");
  4. error_reporting(0);
  5. if($_SERVER['REQUEST_METHOD']=="POST")
  6. {
  7. $username= $_POST['username'];
  8. $password=$_POST['password'];
  9. if(!$username && !$password)
  10. {
  11. echo json_encode(array("error"=>true,"message"=>"Need username and password for login"));
  12. }
  13. else
  14. {
  15. $dbcon=new mysqli("localhost","root","","php");
  16. $sql="SELECT `user_id`, `username`, `fullname`, `password` FROM `user` WHERE username='user' and password='123456';";
  17. $result=$dbcon->query($sql);
  18. if($result->num_rows>0)
  19. {
  20. $row=$result->fetch_assoc();
  21.  
  22. $user=array(
  23. 'user_id'=>$row['user_id'],
  24. 'username'=>$row['username'],
  25. 'fullname'=>$row['fullname']
  26. );
  27.  
  28. echo json_encode(array("error"=>false,"message"=>"Login Success","data"=>$user));
  29. }
  30. else
  31. {
  32. echo json_encode(array("error"=>true,"message"=>"Wrong username or password"));
  33. }
  34. }
  35. }
  36. else
  37. {
  38. echo json_encode(array("error"=>true,"message"=>"Only POST Method allows"));
  39. }
Add Comment
Please, Sign In to add comment