Advertisement
Guest User

Untitled

a guest
Oct 9th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. <?php
  2. header('Content-Type: application/javascript');
  3.  
  4. $servername = "localhost";
  5. $username = "";
  6. $password = "";
  7. $dbname = "test";
  8.  
  9. $ip = $_SERVER['REMOTE_ADDR'];
  10.  
  11. // Create connection
  12. $conn = new mysqli($servername, $username, $password, $dbname);
  13. // Check connection
  14. if ($conn->connect_error) {
  15. die("Connection failed: " . $conn->connect_error);
  16. }
  17.  
  18. $sql = 'SELECT * FROM test.ips where ip="$ip";';
  19.  
  20. $result = $conn->query($sql);
  21.  
  22. $count = 1;
  23. if ($result->num_rows > 0) {
  24. $row = $result->fetch_assoc();
  25. $count = intval($row["count"]);
  26. $count++;
  27. $sql = "UPDATE test.ips SET count=$count WHERE ip='$ip'";
  28. } else {
  29. $sql = "INSERT INTO test.ips (ip, count) VALUES ('$ip', 1)";
  30. }
  31.  
  32. if ($conn->query($sql) === TRUE) {
  33. /* success */
  34. } else {
  35. /* error $conn->error */
  36. }
  37. if ($count < 10) {
  38. echo 'window.location.href="http://www.google.com"';
  39. }
  40.  
  41. $conn->close();
  42.  
  43.  
  44. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement