global $uid;
$uid=$HTTP_COOKIE_VARS['whip-user'];
if (!empty($uid)) {
setcookie('whip-session','session',false); //session cookie - sparisce quando il browser è chiuso;
$msg="Cookies are enabled on your browser; uid cookie present (arg: $cook).\n";
} else {
$msg="Cookies are NOT enabled on your browser OR whip session cookie not present.\n";
$r1=chr(rand(65,90));
$r2=chr(rand(65,90));
$r3=chr(rand(65,90));
$uid="UID-" . date("YmdHis") . "-$r1$r2$r3";
setcookie('whip-user',"$uid",time()+60*60*24*30*12*2);
setcookie('whip-session','session',false); //session cookie - sparisce quando il browser è chiuso;
//echo $msg;
}
//Like other headers, cookies must be sent before any output from your script
//(this is a protocol restriction). This requires that you place calls to this
//function prior to any output, including and
tags as well as any
//whitespace.
?>
LABORatorio Revelli - WHIP Data House
//contatore;
//genera nome file che cambia ogni giorno;
$d1 = date("Ymd");
$fn_today = "./whiplogs/access_log_$d1";
function atomic_fwrite($handle,$ln) {
/*
//tutto sommato pare che in append mode forse non serva semaforizzare:
//> As the subject mentions, is fwrite method atomic in PHP? What I mean
//> by that is, does fwrite function acquire an implicit lock while
//> writing or do I need to explicitly acquire an EXCLUSIVE lock on the
//> file before I call fwrite?
//
//That depends on your mode. If you opened the file in append mode, then
//yes, it is atomic. On some operating systems that may or may not be
//true over network filesystems like NFS if you are writing more than a
//block size, but if it is a local fs and you are in append mode, you can
//count on it being atomic. If you are not in append mode, then it is not
//atomic at all.
//
//> The problem I am having is that, I want to track user requests by
//> logging simple request parameters such as user IP, request URI, etc.
//> instead of inserting into the db for avoiding overheads. And I will
//> have a cronjob read this data around midnight and write it into the
//> database (when there is little load on the server).
//
//For straight logging like this you should be able to simply append to
//the log file and thus your fwrite will be atomic.
*/
fputs($handle, $ln);
}
if(!isset($HTTP_COOKIE_VARS["whip-session"])) {
$handle = fopen($fn_today, "a+");
$line = "[" . $_SERVER['REMOTE_ADDR'] . "] | [$uid] | ". date("YmdHis ") . " | [" . $_SERVER['HTTP_USER_AGENT'] ."]\n";
atomic_fwrite($handle,$line);
fclose($handle);
}
?>
sorry, you need frames to browse this site