auth.php 873 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. // Gasteizko Margolariak API v3 //
  3. // $_POST valid parameters
  4. define('POST_USER', 'user');
  5. define('POST_PASS', 'pass');
  6. // Error messages
  7. define('ERR_USER', '-USER:');
  8. include('functions.php');
  9. $con = startdb();
  10. // Error control
  11. $error = "";
  12. // Get params
  13. $user = mysqli_real_escape_string($con, $_POST[POST_USER]);
  14. $pass = mysqli_real_escape_string($con, $_POST[POST_PASS]);
  15. //Validate user
  16. $uid = login($con, $user, $pass);
  17. if ($uid == -1){
  18. error_log(":SECURITY: Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
  19. $error = $error . ERR_USER . mysqli_real_escape_string($con, $_POST[GET_USER]);
  20. error_log($error);
  21. http_response_code(403); // Forbidden
  22. exit(-1);
  23. }
  24. else{
  25. http_response_code(204); // No content
  26. }
  27. ?>