note 41750 added to function.in-array

From: Date: Wed, 21 Apr 2004 15:07:23 +0000
Subject: note 41750 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-68444@lists.php.net to get a copy of this message
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; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+41750 Delete -- http://master.php.net/manage/user-notes.php?action=delete+41750&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+41750&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#68444) next »