Page Counter v1
referrer
remote addr38.103.63.17
Have to control file permissions on the dir where the counter files live
May need to refresh FTP file listing when create a new file
$PHP_SELF starts out as /dir1/filexxx.php
convert it to ==> dir1.filexxx.php
strip off leading slash so all files are in one counter directory.
change remaining slashes to periods again so all files are in one counter directory
PHP Source Code (HTML newlines removed):
echo "starting php";
$temp = substr($PHP_SELF, 1); //strip off leading slash substring
$temp = str_replace("/", ".", $temp); //replace all slashes with underscores
$myfile = "../mikescounterfiles/" . $temp . ".txt"; //all in one dir, sep file per web page
if (is_file($myfile))
{echo "$myfile IS a file";
if (is_readable($myfile)) {echo "it is readable";}
else {echo "it is NOT readable"; exit;}}
else
{echo "$myfile is NOT a file, creating it";
$fileptr = fopen($myfile, "a"); //create it
if (!$fileptr) {echo "error opening file to create it. maybe";}
fputs($fileptr, "0 | put timestamp here later");
fclose($fileptr);
echo "created file with one line";}
$fileptr = fopen($myfile, "r+"); // R+ is open for read/write
if (!$fileptr) {echo "error opening file for read/write access"; exit;}
$myarray = fgetcsv($fileptr, 300, "|"); //read a line and parse it into an array
if (!$myarray) {echo "error reading counter file with fgetcsv()"; exit;}
echo "number of data fields=" . count($myarray);
echo "counter was=>" . $myarray[0]. "*";
echo "2nd field=>" . $myarray[1]. "*";
$myarray[0] = $myarray[0] + 1; //increment counter
$outline = $myarray[0] . "|" . $myarray[1];
$tfflag = rewind($fileptr); //back to the front of the file
if (!$tfflag) {echo "error rewinding counter file"; exit;}
$numbytes = fwrite($fileptr, $outline);
if (!numbytes) {echo "error updating counter file"; exit;}
$tfflag = fclose($fileptr);
if (!$tfflag) {echo "error closing counter file";}
echo "done with php";
starting php
../mikescounterfiles/.TXT IS a file
it is readable
number of data fields=2
counter was=>1093<=
2nd field=>put timestamp here laterrr<=
done with php
|
Viewed 19069 times since July 17,2007 (63 per day over 303.1 days) |
Home
=> PHP Projects |
| Page: www.michaelhorowitz.com |
Last Updated:
May 24, 2005 5 PM |
|
| Prior to you, the last person to look at this web page did so on | Thursday, May 15, 2008 8:20:06 AM |
| Current time on the server is | Thursday, May 15, 2008 8:20:14 AM |
|
There have been 99322 page views of these PHP pages since February 10, 2004 for an average of 64 per day over 1,555.5 days
The last 5 people to view this web site were from these IP addresses:
| 38.103.63.17 | no name found |
| 66.249.65.71 | crawl-66-249-65-71.googlebot.com |
| 59.96.24.52 | no name found |
| 61.246.177.137 | egress-del1.globallogic.com |
| 67.195.37.107 | llf320021.crawl.yahoo.net |