Guest User

Untitled

a guest
May 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. function log_ip(){
  2. //Includes the mysql/mysqli connect file
  3. include 'includes/mysqli_connect.php';
  4. //Gets the ip address of the client and stores it in $ip variable
  5. $ip = $_SERVER['REMOTE_ADDR'];
  6.  
  7. //Checking if ip exists already in log(Queries written in mysqli, you will need to make changes for mysql)
  8. $check_exist = "SELECT * from log where ip = '$ip'";
  9. $run_check = mysqli_query($link, $check_exist);
  10. //Find out how many rows with the same ip exists and stores the result in $check
  11. $check = mysqli_num_rows($run_check);
  12.  
  13. //If there is more than 0 rows with the same ip then it updates visited with +1
  14. if($check != 0){
  15. $row = mysqli_fetch_assoc($run_check);
  16. //The code to add 1 to the amount of times visited, if visited times is 2, then 1+2 is done here
  17. $visited_update = 1 + $row['visited'];
  18.  
  19. //the sql query to update the visited times
  20. $update = "UPDATE `log` SET `visited` = '$visited_update' WHERE ip = '$ip'";
  21. $run_up = mysqli_query($link, $update);
  22. //If there is no rows with the ip we found then we insert the ip into our log with visited times set to 1
  23. } else {
  24. $log = "INSERT into log (ip, visited) VALUES ('$ip', '1')";
  25. $insert = mysqli_query($link, $log);
  26. }
  27. }
Add Comment
Please, Sign In to add comment