Jump to content

[SOLVED] Tracking IP


spires

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/39825-solved-tracking-ip/#findComment-192394
Share on other sites

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'");
}
?>

Link to comment
https://forums.phpfreaks.com/topic/39825-solved-tracking-ip/#findComment-192397
Share on other sites

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)

 

Link to comment
https://forums.phpfreaks.com/topic/39825-solved-tracking-ip/#findComment-192416
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/39825-solved-tracking-ip/#findComment-192436
Share on other sites

Archived

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

×
×
  • 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.