Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/14107-tracking-visitors/
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]
Link to comment
https://forums.phpfreaks.com/topic/14107-tracking-visitors/#findComment-55413
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
Link to comment
https://forums.phpfreaks.com/topic/14107-tracking-visitors/#findComment-55601
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.