SQL PHP HTML ASP JavaScript articles and free scripts to download
 

How to insert visitor IP address and referrer in a table

When visitors come to our website we can collect visitors IP address, referrer, browser details and others details and store them in a MySQL table. Note that this is one of the examples of storing some minimum details of the visitors and not a full script to collect all details. We will try to log minimum important details of the visitors like ip address, referrer, browser details, time of page access and a unique page name. We will keep one unique page name for each page as we will be using same table for all the pages of the site. So the variable to collect the unique page name of the page is assign different values in different pages.

Note that the script already have mysql connection and here is the code to be used for logging visitor details to mysql table. We have used one sql insert query to add record to the table on each opening of the page.

$tm=time();
$ref=@$HTTP_REFERER;
$agent=@$HTTP_USER_AGENT;
$ip=@$REMOTE_ADDR;
$strSQL = "INSERT INTO track(tm, ref, agent, ip, tracking_page_name) VALUES ('$tm','$ref','$agent','$ip','$tracking_page_name')";
$test=mysql_query($strSQL);

The above code will insert the visitor details to the table name track in mysql database.

You can read the article on reading data from table to display the data of the visitors in a page.

Here is the dump of the table track
CREATE TABLE `track` (
`id` int(6) NOT NULL auto_increment,
`tm` varchar(15) NOT NULL default '',
`ref` varchar(250) NOT NULL default '',
`agent` varchar(250) NOT NULL default '',
`ip` varchar(20) NOT NULL default '',
`ip_value` int(11) NOT NULL default '0',
`domain` varchar(20) NOT NULL default '',
`tracking_page_name` varchar(10) NOT NULL default '',
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;

Discuss this tutorial at forum


Further readings
Getting IP address of visitors
Collecting visitor referrer
Logging Visitor details to MySQL details
Getting details of Visitors
 

Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript
PHP Tutorial Index
Popular Tutorials
Drop down list
File Upload
Signup script
Member Login
Line Graph
PHP MySQL Paging
PHP Calendar
PHP Tutorials
Date & Time
Array
String Functions
Math Functions
Form Handling
File Handling
Comment Posting
Content Management
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.