counter.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:21:59 2007 from counter.php 2007/05/31 2.2 KB bytes.


<html>
<head>
<title>PHP Counter</title>
</head>
<body>
<h1 align="center">Simple PHP Counter</h1>
<p>
<?php
$txt_file = "counter.txt";
$ip_file = "ip.txt";
$msgline = '';
$rip = $_SERVER['REMOTE_ADDR'];
if( strlen($rip) == 0 ) {
   $rip = '198.168.1.1';   // use a dummy
}
$dat = date('d');
$fdate = date('Y/m/d');
$ddate = '9999999';
if(file_exists($txt_file)) {
 $bump = 1;
 $f = fopen( $txt_file, 'r+' );
 $count = fread($f, filesize($txt_file));
 if(file_exists($ip_file)) {
 $lines = file($ip_file);
 foreach ($lines as $line_num => $line) {
 $fpos = strpos( $line, '"' );
 if($fpos === false) {
 // not found in first line!!!
 } else {
 $spos = strpos( $line, '"', $fpos );
 if($spos === false) {
 // failed to find second
 } else {
 $ddate = substr($line,$fpos+1,($spos-$fpos)-2);
 }
 }
 break;
 }
 }
 $ips = '';
 $revisit = '';
 if(file_exists($ip_file)) {
 $open2 = fopen($ip_file, "r");
 $size = filesize($ip_file);
 $ips = fread($open2, $size);
 fclose($open2);
 }
 if($ddate == $dat) {
 // date the SAME
 if(strpos($ips,$rip)) {
 $revisit = "Re-visits on the same day, ".$dat.", are not counted.";
 $bump = 0;   // and contains this IP
 } else {
 if(file_exists($ip_file)) {
 $open3 = fopen($ip_file, "a");
 fwrite($open3,"\n");
 fwrite($open3, $rip);
 fclose($open3);
 }
 }
 } else {
 $open3 = fopen($ip_file, "w");
 fwrite($open3, "DATE= \"$dat\"");
 fwrite($open3, "\n\n");
 fwrite($open3, $rip);
 fwrite($open3, "\n");
 fwrite($open3, $ips);
 fclose($open3);
 }

 if($bump) {
 rewind($f);
 $count++;
 fwrite($f, $count);
 ftruncate($f, ftell($f));
 }
 fclose( $f );
 $s = $count;
 $line = sprintf("%s Count: %s people have visited this page.<br>", $fdate, $s);
 $msgline .= $line;
} else {
 $line = sprintf("Count file [%s] NOT FOUND!<br>", $txt_file );
 $msgline .= $line;
 $msgline .= "You are the FIRST, since the counter file was deleted.<br>";
 $open3 = fopen($txt_file, "w");
 fwrite($open3,"1");
 fclose($open3);
}
$line = sprintf("Visitor IP: %s %s", $rip, $revisit);
$msgline .= $line;
print $msgline."\n";
?>
</p>

</body>
</html>

index

Valid HTML 4.01 Transitional