I've looked everywhere for an answer to this problem...in fact, I've been working on this (rather small) piece of code for a couple of hours now (researching, etc.). I give up for tonight.
Basically, what I am trying to do is make a unique hit counter with minimal lines of code. It will store all the IP addresses in a text file.
First, it checks to see if the current user's IP address is in the text file. If so, it prints the current number of visitors. If not, it adds the new user's IP to the end of the file and displays the new number of visitors. Here's the code:
<?php
$file = "hits.txt";
$ip_list = file($file);
$visitors = count($ip_list);
if (in_array($_SERVER['REMOTE_ADDRESS'], $ip_list))
{
exit ($visitors);
} else {
$fp = fopen($file,"a");
fwrite($fp, "\n$REMOTE_ADDR");
fclose($fp);
echo $visitors++;
}
?>
For some reason, in_array fails to make a match. I've tried to use TRIM and/or STRIPSLASHES just to be safe, but it didn't affect the outcome. It's probably something really simple, I just can't see it.
Any ideas? ~yawn~ Thank! 🙂