Hi,
i'm sorry, but i can't post any other session handler script... 🙂
This is a thing of "newbies"... a counter.
My quest is to do this without overload the db, but storing periodically the access, and i can't use any scheduler (i'm not the host-master...).
Well, a little comment.
This script is in the file i want to count access:
<script><!--
new Image().src = "count.php?name=<name_of_file>";
//--></script>
My site is also an intranet, so more access going from our gateway, so i need also to check for the port....
I will use a file for each counter.
<?php
//check if is the home page access...
if(substr_count($nome,"main")>0) $main=1; else $main=0;
//the real name is name+path
$name=$PATH_TO_DIR.$name;
//clear vars...
$line[0]=0; $line[1]=0; $line[2]=0;
//get IP and PORT of user
$myip=$REMOTE_ADDR;
$curip=$myip.$REMOTE_PORT;
//mask last two number of port:
// Any user can open many browser window...
$curip=substr($curip,0,strlen($curip)-2);
//read file and delete blank.
$line=@file($name);
$line[0]=trim($line[0]); // counter
$line[1]=trim($line[1]); // IP.PORT
$line[2]=trim($line[2]); // day - only for home page counter...
//check if is me or if is previous user
if($myip!="192.168.xxx.xxx" && $curip!=$line[1]){
$line[0]++; //inc access counter
$line[1]=$curip;
if ($main==0) { // if is not the main write it into file.
$handle=fopen($name, "w+");
fwrite($handle,$line[0]."\n".$line[1]);
} else {
if($line[2]!=date("d")) {
//if is tomorrow write all counters
//into db.
require("storedb.php");
}
//update the date and write the file
$line[2]=date("d");
$handle=fopen($name, "w+");
fwrite($handle,$line[0]."\n".$line[1]."\n".$line[2]);
} //exit safety
fclose($handle);
}
header('Content-type: image/gif');
readfile("../gfx/null.gif");
?>
That's all... What you think?