require_once "track.php"; ?>
We assume the reader if familiar with the php environment. This guide will show you what are the most important variables you can use to find out informations about a visitor.
Let’s start with the basics
$_SERVER['HTTP_USER_AGENT']
will return informations about the operating system and the browser ( version ) the visitor is using.This information has to be parsed in order to have nice looking strings you can display on your site. You can download the entire script at the end of the presentation.
$_SERVER['REMOTE_ADDR']
will return the ip of the user visiting the site.
$_SERVER["REQUEST_URI"]
is the name of the current page ( including variables in case we have a php script )
$_SERVER["HTTP_REFERER"]
is the website that send you the visitor.
There are 3 more important things you should know about your visitor. The screen resolution , the country and the city if possible. For the screen resolution is not enough to use php. You need a mix of javascript and php . A good example can be found here. For the country and city there are 2 good alternatives. You can use an API to request info from a remote website based on the ip you are sending or you can use a database ( free or payed ).
The API solution it’s a great idea. Hostip.info “is a community-based project to geolocate IP addresses, making the database freely available”. This solution will probably work great in the future when more people get involved and the results will look like this : exemple.
The real good solution for the moment is to use a database. The idea is simple but requires a few more steps. MaxMind.com offers a free database that can track even the city using an ip.
The steps to you need to take to accomplish this are :
1.Read the installation notes
2.Copy 3 files on your server geoip.inc | geoipcity.inc | geoipregionvars.php download
3.Copy the database on your server ( plain text file ) DB
4.Include this lines in your php file
require_once ‘geoipcity.inc’;
$gi = geoip_open(“GeoLiteCity.dat”,GEOIP_STANDARD);
$record = geoip_record_by_addr($gi,$ip);
$var_country=$record->country_name;
$var_city=$record->city;
geoip_close($gi);
The only catch is the fact that the database is 15 Mega in size but this is only because you want the city info to. You can choose and install only the database for countries that is considerable smaller.
A full working script you can include in your site can be found here.
hi I need your help!
I need to create a track for my flash site when they click on one specific button from my SWF using PHP or XML, whatever it is I need the coding…. thanks!
CH.