Jump to content

Archived

This topic is now archived and is closed to further replies.

smith.james0

Tracking visitors

Recommended Posts

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

Share this post


Link to post
Share on other sites
First run this query: [code]ALTER TABLE your_table_name_here ADD UNIQUE (session_id);[/code]

Then when inserting the new row, you could do something like this: [code]<?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().")");
}
// ...
?>[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.