Guest User

Untitled

a guest
Dec 14th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. <?php
  2.  
  3. include('database2.php');
  4.  
  5. // Access-Control headers are received during OPTIONS requests
  6. if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  7.  
  8. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
  9. header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  10.  
  11. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
  12. header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  13.  
  14. exit(0);
  15. }
  16.  
  17. $conn = mysqli_connect($dbserver, $user, $pass, $db);
  18.  
  19. // Check connection
  20. if (!$conn) {
  21. die("Connection failed: " . mysqli_connect_error());
  22. }
  23.  
  24. echo "Connected successfully";
  25.  
  26. $postdata = file_get_contents("php://input");
  27. if (isset($postdata)) {
  28.  
  29. //THE ERROR IS HERE
  30. $request = json_decode($postdata);
  31. $username = $request->username;
  32. $userpass = $request->userpass;
  33.  
  34. $sql = sprintf("SELECT * FROM account_info where a_username='%s' ",
  35. //WHERE User_Name='%s' AND User_Pass='%s'
  36. mysqli_real_escape_string($conn,$username),
  37. mysqli_real_escape_string($conn,$userpass));
  38. $result=$conn->query($sql);
  39. if ($result->num_rows>0)
  40. { $UserID=0;
  41. while($row=$result->fetch_assoc())
  42. {$UserID=$row["acc_id"];
  43. }
  44. $myobj=array();
  45. array_push($myobj,array('isloggedin'=>'true','userid'=>$UserID));
  46. echo json_encode($myobj);
  47. }
  48.  
  49. else
  50. {
  51. $myobj=array();
  52. array_push($myobj,array('isloggedin'=>'false'));
  53. echo json_encode($myobj);
  54. }
  55. }
  56. ?>
Add Comment
Please, Sign In to add comment