smith.james0 Posted July 9, 2006 Share Posted July 9, 2006 At the moment I have a db for people on line (XX visitors browsing).It has the following fields.session_idip_addressrefurluser_agentmktimeand auto incromental idIt 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 More sharing options...
Daniel0 Posted July 10, 2006 Share Posted July 10, 2006 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 More sharing options...
smith.james0 Posted July 10, 2006 Author Share Posted July 10, 2006 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.