note 41750 deleted from function.in-array by betz
| From: | betz@php.net | Date: | Wed, 21 Apr 2004 16:10:41 +0000 |
| Subject: | note 41750 deleted from function.in-array by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-68458@lists.php.net to get a copy of this message | ||
Note Submitter:
----
i couldn't find a decent php UNIQUE hit counter script. so i made one using using in_array..
<?
$file = file("myhits.txt");
//create a blank file called myhits.txt to be read as an array
$ip = getenv("REMOTE_ADDR");
$content = $ip."\n";
if (in_array("$ip\n", $file)) {
//note above that it should be blackslash n
$hits = count($file);
echo $hits;
}
else {
$handle = fopen ("myhits.txt", "a");
fwrite ($handle, $content);
fclose($handle);
$hits = count($file);
echo $hits;
}
?>