Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function log_ip(){
- //Includes the mysql/mysqli connect file
- include 'includes/mysqli_connect.php';
- //Gets the ip address of the client and stores it in $ip variable
- $ip = $_SERVER['REMOTE_ADDR'];
- //Checking if ip exists already in log(Queries written in mysqli, you will need to make changes for mysql)
- $check_exist = "SELECT * from log where ip = '$ip'";
- $run_check = mysqli_query($link, $check_exist);
- //Find out how many rows with the same ip exists and stores the result in $check
- $check = mysqli_num_rows($run_check);
- //If there is more than 0 rows with the same ip then it updates visited with +1
- if($check != 0){
- $row = mysqli_fetch_assoc($run_check);
- //The code to add 1 to the amount of times visited, if visited times is 2, then 1+2 is done here
- $visited_update = 1 + $row['visited'];
- //the sql query to update the visited times
- $update = "UPDATE `log` SET `visited` = '$visited_update' WHERE ip = '$ip'";
- $run_up = mysqli_query($link, $update);
- //If there is no rows with the ip we found then we insert the ip into our log with visited times set to 1
- } else {
- $log = "INSERT into log (ip, visited) VALUES ('$ip', '1')";
- $insert = mysqli_query($link, $log);
- }
- }
Add Comment
Please, Sign In to add comment