[thelist] Tracking users on a site

Kristy Frey kristenannfrey at yahoo.com
Thu Mar 7 11:48:11 CST 2002


> Just want to know if anyone has any ideas on how I can track users of a
> site. My server logs don't show what I need.

Here is a possible PHP solution:

I created this function in a library that i always include that gives me a text file of comma
separated values.

I call the function from every page/script passing in the appropriate log and cookie name for the
site (since I use this same function for different sites).

function RecordHit($a_logfile,$a_cookie_name)
{
 global $HTTP_COOKIE_VARS;
 if(isset($HTTP_COOKIE_VARS[$a_cookie_name])){$v_cookie=$HTTP_COOKIE_VARS[$a_cookie_name];}
 else{$v_cookie='NO COOKIE SET';}
 $file1handle=fopen($a_logfile, "a");
 fputs($file1handle,chr(34).microtime().chr(34).chr(44));
 fputs($file1handle,chr(34).$GLOBALS['REMOTE_ADDR'].chr(34).chr(44));
 fputs($file1handle,chr(34).$GLOBALS['SCRIPT_NAME'].chr(34).chr(44));
 fputs($file1handle,chr(34).$GLOBALS['HTTP_USER_AGENT'].chr(34).chr(44));
 fputs($file1handle,chr(34).$GLOBALS['HTTP_REFERER'].chr(34).chr(44));
 fputs($file1handle,chr(34).$v_cookie.chr(34).chr(13).chr(10));
 fclose($file1handle);
}
> What I want is to know how long users stay on my site and what pages they
> looked at.

This gives you all the info you need to write log analysis code later (for example, you could
calculate the time between page hits for a user - provided they accept a cookie)
- Kristy


=====
----------------------------------------------------------
I apologize for the ads/links below - Yahoo put them there.
That's what I get for using free mail
----------------------------------------------------------

__________________________________________________
Do You Yahoo!?
Try FREE Yahoo! Mail - the world's greatest free email!
http://mail.yahoo.com/



More information about the thelist mailing list