Created
July 12, 2017 09:19
-
-
Save ManishLSN/5b7ddc6086bfffe7b6c26e9a02cf8983 to your computer and use it in GitHub Desktop.
Save IP address and referrer of our page Let's suppose we want to record the IP address and Referrer of all visitors to our page. The script bellow may be placed within the code of our page and it will create two files to store both data: "ips_file.txt" to store IP addresses and "ref_file.txt" to store referrers. Additionally, this script may be…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// save ip | |
$ip=$_SERVER["REMOTE_ADDR"]; | |
if ($ip!=""){ | |
$ipfile= "ips_file.txt"; | |
$allips = file_get_contents ($ipfile); | |
if (strpos($allips," $ip ")>0){ | |
$allips = preg_replace ("/ $ip /"," $ip x",$allips); | |
$tempvar= fopen($ipfile, "w"); | |
fwrite ($tempvar, $allips); | |
fclose($tempvar); | |
}else{ | |
$tempvar = fopen($ipfile, "a"); | |
fwrite ($tempvar, " $ip x\n"); | |
fclose($tempvar); | |
} | |
} | |
// save referrer | |
$ref=$_SERVER["HTTP_REFERER"]; | |
if (strpos($ref,"mydomain.com")==0 and $ref!=""){ | |
$refffile= "ref_file.txt"; | |
$tempvar = fopen($refffile, "a"); | |
fwrite ($tempvar, $ref."\n"); | |
fclose($tempvar); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment