spires Posted February 23, 2007 Share Posted February 23, 2007 Hi Everyone, Do any of you know how i would go about tacking IP address? I want to find a way of seeing visitors movments, Where they go from page to page. Thanks Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 You would have to find out what page they are on by using $_SERVER['PHP_SELF'], then log each page they view as they view them. Quote Link to comment Share on other sites More sharing options...
oracle259 Posted February 23, 2007 Share Posted February 23, 2007 Well you could use your php environmental variables to capture the users ip address, the timestamp, and last page visited and store the information in a mysql database then run a search ordered by timestamp. Checkout the following link for some ideas http://www.php.net/manual/en/reserved.variables.php Be sure to check out REMOTE_ADDR and HTTP_REFERER Quote Link to comment Share on other sites More sharing options...
spires Posted February 23, 2007 Author Share Posted February 23, 2007 Hi, Thanks for your help. I'll go check it out. Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 Here's a friggin sweet script. It gets the information and puts it into a MySQL database. It can give you: the php sessionID the number of pages the viewed The page they entered on The page that led them to your site (referrer) When they viewed your site (year, month, weekDay, date, hour) I forgot what the number variable is It almost tells their browser resolution but I had trouble making the php and javascript work together Their browser and version Their operating system Their IP address AND Their internet host (isp) Sorry you are going to have to make the MySQL table yourself. <? session_start(); header("Cache-control: private"); //IE 6 Fix $connection=mysql_connect("host","username","password") or die(mysql_error()); $db=mysql_select_db("databaseName",$connection); function iif($expression, $returntrue, $returnfalse = '') { return ($expression ? $returntrue : $returnfalse); } $sessionID = session_id(); $ipaddress = $_SERVER['REMOTE_ADDR']; $page = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}"; $page .= iif(!empty($_SERVER['QUERY_STRING']), "?{$_SERVER['QUERY_STRING']}", ""); $referrer = $_SERVER['HTTP_REFERER']; $curYear = date("Y"); $month = date("F"); $weekDay = date("l"); $date = date("d"); $hour = date("G") + 2; $resolution = '<script type="text/javascript"> document.write(screen.width+"x"+screen.height); </script>'; $useragent = $_SERVER['HTTP_USER_AGENT']; $remotehost = @getHostByAddr($ipaddress); if(strpos($useragent, 'Windows NT 5.1') != 'false'){ $os = 'Windows XP'; } else if(strpos($useragent, 'Windows 98') != 'false'){ $os = 'Windows 98'; } else if(strpos($useragent, 'Windows 95') != 'false'){ $os = 'Windows 95'; } else { $os = $useragent; } if (!empty($_SERVER['HTTP_USER_AGENT'])){ $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT']; } else if (!empty($HTTP_SERVER_VARS['HTTP_USER_AGENT'])){ $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; } else if (!isset($HTTP_USER_AGENT)){ $HTTP_USER_AGENT = ''; } if (ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)){ $browserVersion = $log_version[2]; $browser_agent = 'Opera'; } else if (ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)){ $browserVersion = $log_version[1]; $browser_agent = 'Internet Explorer'; } else if (ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)){ $browserVersion = $log_version[1]; $browser_agent = 'OmniWeb'; } else if (ereg('Netscape([0-9]{1})', $HTTP_USER_AGENT, $log_version)){ $browserVersion = $log_version[1]; $browser_agent = 'Netscape'; } else if (ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)){ $browserVersion = $log_version[1]; $browser_agent = 'Mozilla Firefox'; } else if (ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version)){ $browserVersion = $log_version[1]; $browser_agent = 'Konqueror'; } else { $browserVersion = 0; $browser_agent = $HTTP_USER_AGENT; } if(!$referrer){ $referrer = 'Typed it in'; } if (!session_is_registered("counted")){ $count = mysql_query("INSERT INTO `hits` (`sessionID`, `pages`, `entered`, `referrer`, `year`, `month`, `weekDay`, `date`, `hour`, `number`, `resolution`, `browser`, `version`, `os`, `ip`, `host`) VALUES ('$sessionID', '1', '$page', '$referrer', '$curYear', '$month', '$weekDay', '$date', '$hour', '0', '$resolution', '$browser_agent', '$browserVersion', '$os', '$ipaddress', '$remotehost')"); session_register("counted"); } else { $count = mysql_query("UPDATE hits SET pages=(pages + 1), exited='$page' WHERE year='$curYear' AND month='$month' AND date='$date' AND sessionID='$sessionID' AND host='$remotehost' AND ip='$ipaddress'"); } ?> Quote Link to comment Share on other sites More sharing options...
spires Posted February 23, 2007 Author Share Posted February 23, 2007 WOW, Now thats what i'm looking for. I'm getting into internet marketing, and it is all about testing, This is exactly what i need, Now all i've got to do is figure it out :-) Thanks Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 Here is the information for the MySQL table. It's not the code to enter into the database, but it will help you know what kind of table you need to make. Glad I could help! Field Type sessionID varchar(255) pages varchar(25) entered varchar(255) exited varchar(255) referrer text year varchar(25) month varchar(25) weekDay varchar(25) date varchar(25) hour varchar(25) number varchar(25) resolution varchar(255) browser varchar(25) version varchar(25) os varchar(25) ip varchar(25) host varchar(255) Quote Link to comment Share on other sites More sharing options...
spires Posted February 23, 2007 Author Share Posted February 23, 2007 Thanks, thats a great help. One last thing, Does this code go on to every page? Or can i place it into a function, and just call up the function? Thanks again Quote Link to comment Share on other sites More sharing options...
ldsmike88 Posted February 23, 2007 Share Posted February 23, 2007 I have it on every page. It's probably not very smart of me. You could probably put it in a function. If the function doesn't work you might be able to put it in a file all by itself and just include the file. The best way to find out is to try it out and see I guess. Good luck! Michael Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.