How much site visitor info can I collect?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
fatman
Forum Commoner
Posts: 47
Joined: Fri Jul 21, 2006 11:18 am
Location: Portugal

How much site visitor info can I collect?

Post by fatman »

I currently collect IP, Browser and date/time info on every visitor to my site for my stats.

Code: Select all

// Check if the referer is your site if not then add record 
 if (preg_match ("/www.holidaypropertyrentalportugal.org/i", "$HTTP_REFERER")) { 
    mysql_close($connection); 
} else { 

// If you cant resolve domain use IP address 
if ($REMOTE_HOST == "") { 
    $host = $REMOTE_ADDR; 
} else { 
    $host = $REMOTE_HOST; 
} 

if ($host == '67.15.16.30') // Kill link something
{} else {
if( empty( $HTTP_REFERER ) or '' == $HTTP_REFERER ) { 
    $HTTP_REFERER = 'No Referer'; 
} 
$file2 = basename($PHP_SELF);

mysql_query ("INSERT INTO myStats (browser, date, host, referer, page, control_date) VALUES ('$browser','$date','$host','$HTTP_REFERER','$file2','$control_date' )"); 
}
Can I collect more usefull info?

I have seen sites (e.g. Blogs) take my name from my PC and use it to welcome me even though I have not entered it.

How is this done, and is there any way to collect info like location, language and email?

This info would be great for compiling demographics on my visitors. :?:
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

There's all kind of information you can track. This is the code I use for IPs:

Code: Select all

	if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) === true) {
	
		if(isset($_SERVER['HTTP_CLIENT_IP']) === true) {
			$_SESSION['session_proxy_ip'] = $_SERVER['HTTP_CLIENT_IP'];
		} else {
			$_SESSION['session_proxy_ip'] = $_SERVER['REMOTE_ADDR'];
		}
		
		$_SESSION['session_ip'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
		
	} else{
		
		if(isset($_SERVER['HTTP_CLIENT_IP']) === true) {
			$_SESSION['session_ip'] = $_SERVER['HTTP_CLIENT_IP'];
		} else {
			$_SESSION['session_ip'] = $_SERVER['REMOTE_ADDR'];
		}
		
	}
Google Analytics tracks: Browser Versions, Platform Versions, Screen Resolutions, Screen Colors, Languages, Java Enabled, Flash Version, Connection Speed, and Hostnames. Of course, much of their tracking is done client-side.
I have seen sites (e.g. Blogs) take my name from my PC and use it to welcome me even though I have not entered it.
That sounds like OpenID or maybe something you would see on a large Blogger network (that you gave such information to).
How is this done, and is there any way to collect info like location, language and email?
For location, there GeoIP. For language, the HTTP request header Accept-Language.
Post Reply