Guest User

key checker

a guest
Aug 19th, 2013
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. //connect to database by including connection file.
  4. require_once('connect.php');
  5. //get variables passed from form.
  6. $key = $_POST['key'];
  7. //sanitize input to prevent SQL injection
  8. $key = strip_tags($key);
  9. // further sanitization using mysql real escape
  10. $key = mysql_real_escape_string($key);
  11. //query database to first check that the key exists.
  12. $sql = "SELECT * FROM wills95_licence_key_generator.licencekeys WHERE keycode = $key ";
  13. //Run the query to find all results.
  14. $query = mysql_query($sql);
  15. echo $query;
  16. //get the array
  17. $key_array = mysql_fetch_array($query);
  18. echo $key_array;
  19. $value = $key_array['keycode'];
  20. echo $value;
  21.  
  22. //Count the number of rows to ensure 1 row is found
  23.  
  24. //echo the value of rows to ensure row count is working correctly.
  25. echo "This should return the value of 1: ";
  26. echo "<br />";
  27. echo $rows;
  28. //If statement to confirm that row exists.
  29. If($rows==1) {
  30. //select key and retrieve the active setting, this will return either YES or NO.
  31. $sql_2 = "SELECT active FROM wills95_licence_key_generator.licencekeys WHERE keycode = $key ";
  32. $query_2 = mysql_query($sql_2);
  33. //now echo out the variable to see what the output is.
  34. echo "The result of your key check is below, if NO is displayed, the key is not activated, if YES is displayed, the key has already been activated and is no longer valid";
  35. echo $query_2;
  36.  
  37.  
  38. }  else {
  39.  
  40. echo "That key was not found in our database";
  41.  
  42. }
  43.  
  44. //end script.
  45.  
  46. //*Copyright William Shelley 2013*//
  47. ?>
Advertisement
Add Comment
Please, Sign In to add comment