Jump to content


Photo

Tracking visitors


  • Please log in to reply
2 replies to this topic

#1 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 09 July 2006 - 05:31 PM

At the moment I have a db for people on line (XX visitors browsing).
It has the following fields.
session_id
ip_address
refurl
user_agent
mktime
and auto incromental id

It does the job at the moment but i want to get more from it, like the total unique visitors.

The session ID is unique, like the ip but i have three or four rows in the db with the same session id, this would corrupt the figures. I need some way of querying the db to return the amount of rows where the session id is unique if you know what i mean  ???

Can anyone point me in the right direction?

Thanks James


#2 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 10 July 2006 - 06:27 AM

First run this query:
ALTER TABLE your_table_name_here ADD UNIQUE (session_id);

Then when inserting the new row, you could do something like this:
<?php
// ...
$query = @mysql_query("SELECT * FROM your_table_name_here WHERE ip_address='{$_SERVER['REMOTE_ADDR']}'");
if(@mysql_get_num_row($query) <= 0)
{
	@mysql_query("INSERT INTO your_table_name_here (session_id,ip_address,refurl,user_agent,mktime) VALUES ('$session_id','$_SERVER['REMOTE_ADDR']','$_SERVER['USER_AGENT']',".time().")");
}
// ...
?>


#3 smith.james0

smith.james0
  • Members
  • PipPipPip
  • Advanced Member
  • 122 posts

Posted 10 July 2006 - 03:29 PM

I thought a session id stayed the same as long as the browser was open?

This the code i use at the moment

$page = basename ($_SERVER['PHP_SELF']);

if(!session_is_registered('online')){
session_register('online');
    $sql = "INSERT INTO ******* (session_id, activity, ip_address, refurl, user_agent, page)
    VALUES ('".session_id()."', now(), '{$_SERVER['REMOTE_ADDR']}', '{$_SERVER['HTTP_REFERER']}', '{$_SERVER['HTTP_USER_AGENT']}' , '$page')";
    mysql_query($sql, $db) or die ("Invalid query1" .mysql_error());

} else {
    if(session_is_registered('user_id')){
        $sql = "UPDATE ******* SET activity=now(), member='y' WHERE session_id='".session_id()."'";
mysql_query($sql, $db) or die ("Invalid query2");
    }
}
if(session_is_registered('online')){       
    $sql = "UPDATE ******* SET activity=now(), page='$page' WHERE session_id='".session_id()."'";
mysql_query($sql, $db) or die ("Invalid query3");
}


Thanks James




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users