bhalos
01-19-2005, 02:37 PM
Ive made this simple counter code which should count how much first time visitors i get. It stores that number in uv.txt and stores the ip adresses in ipfile.txt
But the problem is it doesnt work. :(
If it finds the ip in ipfile.txt then it shouldnt do anything but if it does find the ip it should increase the number in uv.txt and add the ip to ipfile.txt
Ive made the loop stop when it hits "einde" if it then hasnt found the ip then it should start logging.
This all works but ive manually written "einde" in the txt file so that it knows when to log. (perhaps anyone has a better suggestion?)
But what happens is that it adds the new ip to ipfile.txt on the end so "einde"is no longer at the end and then the counter wont work anymore.
Help?
$ip2="ipfile.txt";
$ipfile=file($ip2);
$num_ip = $REMOTE_ADDR;
$count=count($ipfile);
for ($i=0;$i<$count;$i++)
{
$check=chop($ipfile[$i]);
if ($num_ip==$check)
{ break; }
elseif ($check==einde)
{ $log = nee;}
}
if ($log == nee)
{
$counternum = "uv.txt";
$fp = fopen($counternum,rw);
$num = fgets($fp,9999);
fclose($fp);
$fp = fopen($counternum,w);
$num += 1;
// print "$num"; (enable to display counter on webpage)
fputs($fp, $num);
fclose($fp);
$num_ip = $REMOTE_ADDR;
$num_ip = "$num_ip";
$apro_ip=fopen($ip2,"a+");
fwrite($apro_ip,$num_ip);
fclose($apro_ip);
}
But the problem is it doesnt work. :(
If it finds the ip in ipfile.txt then it shouldnt do anything but if it does find the ip it should increase the number in uv.txt and add the ip to ipfile.txt
Ive made the loop stop when it hits "einde" if it then hasnt found the ip then it should start logging.
This all works but ive manually written "einde" in the txt file so that it knows when to log. (perhaps anyone has a better suggestion?)
But what happens is that it adds the new ip to ipfile.txt on the end so "einde"is no longer at the end and then the counter wont work anymore.
Help?
$ip2="ipfile.txt";
$ipfile=file($ip2);
$num_ip = $REMOTE_ADDR;
$count=count($ipfile);
for ($i=0;$i<$count;$i++)
{
$check=chop($ipfile[$i]);
if ($num_ip==$check)
{ break; }
elseif ($check==einde)
{ $log = nee;}
}
if ($log == nee)
{
$counternum = "uv.txt";
$fp = fopen($counternum,rw);
$num = fgets($fp,9999);
fclose($fp);
$fp = fopen($counternum,w);
$num += 1;
// print "$num"; (enable to display counter on webpage)
fputs($fp, $num);
fclose($fp);
$num_ip = $REMOTE_ADDR;
$num_ip = "$num_ip";
$apro_ip=fopen($ip2,"a+");
fwrite($apro_ip,$num_ip);
fclose($apro_ip);
}