Sami Barboura Sami Barboura - 11 months ago 59
PHP Question

unique ip visit redirect in php without mysql

i'm sorry if my request seems silly .
i've looked for a long time for this but no luck.
basically what i'm trying to do is : i want when a visitor visits my link'http:/ /mysite. com/redirect .php' , my php script gets his ip address, checks if it exists in an array of ips stored in a file 'hits.txt', if it does then redirect him to another page say''
if it doesn't then store his ip address in the file then redirect him to another page say ''.
so later when he comes back to visit again he gets redirected to
ofcourse my purpose eventually is to make a unique ip visits script.
if you have an idea how to do it without database and sql i'll be grateful, if u think it can only be done with sql then please suggest me the easiest way.
my code so far but it doesn't work :

// Unique Hits PHP Script
// ----------- March 2004
// Contact author:

$log = 'hits.txt';

$IP = getenv (REMOTE_ADDR);
$add = true;
$hits = 0;

if (!file_exists ($log)) {
echo "Error: $log does not exist.";

$h = fopen ($log, 'r');

if (in_array($IP, array($h))){

$fp = fopen('hits.txt', 'a');
fwrite($fp, "'" );
fwrite($fp, $IP );
fwrite($fp, "'" );
fwrite($fp, ',' );




appreciated and thankful to you guys .

Answer Source

You could use cookies for this. It's probably a more reliable way than using IP adress, since a lot of people have a dynamic IP anyway.