Advertisement
Guest User

Untitled

a guest
Oct 1st, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. if (isset($_SERVER['HTTP_ORIGIN'])) {
  2. header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
  3. header('Access-Control-Allow-Credentials: true');
  4. header('Access-Control-Max-Age: 86400'); // cache for 1 day
  5. }
  6. // Access-Control headers are received during OPTIONS requests
  7. if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
  8.  
  9. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
  10. header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
  11.  
  12. if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
  13. header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
  14.  
  15. exit(0);
  16. }
  17. $dbhost='localhost';
  18. $user='root';
  19. $password='';
  20. $dbName='testdatabase';
  21. $con = mysqli_connect("$dbhost" , "$user" , "$password");
  22.  
  23. mysqli_select_db($con,"testdatabase");
  24.  
  25. $postdata = file_get_contents("php://input");
  26.  
  27. if (isset($postdata)) {
  28. $request = json_decode($postdata);
  29. //$username = $request->username;
  30.  
  31. $username = $request->username;
  32.  
  33.  
  34. if ($username != "") {
  35. echo "Server returns: " . $username;
  36. // $sql = mysqli_query($con, "INSERT INTO doctortable (Name, Username, Password)
  37. // VALUES ('TEST', 'TEST', 'TEST')");
  38. }
  39. else {
  40.  
  41. echo "Empty username parameter!";
  42. }
  43. }
  44. else {
  45. echo "Not called properly with username parameter!";
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement