: PHPTrackingVisitors

Welcome :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

Tracking Visitors


There are numerous services to track your site's visitors - visits, refers and clicks. Most of them use embedded Javascript code to keep track of visitors' activity.

Some of the popular ones are :

Cpanel has a server side tracking system to show such statistics called AWStats.

Tracking refers using PHP


Create a MySQL table :
CREATE TABLE `log_referers` (
  `RefererID` bigint(20) NOT NULL auto_increment,
  `FromLink` varchar(1000) NOT NULL,
  `ToLink` varchar(1000) NOT NULL,
  `IP` varchar(16) NOT NULL,
  `Client` text NOT NULL,
  `Entry` datetime NOT NULL,
  PRIMARY KEY  (`RefererID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Referers' AUTO_INCREMENT=1 ;

Add this PHP snippet somewhere at the end of your page.
# Track Referers 
if ($_SERVER['HTTP_HOST'] != "localhost" && isset($_SERVER['HTTP_REFERER']))
 {
	    if (
	       substr($_SERVER['HTTP_REFERER'], 0, strlen("http://mydomain.com")) != "http://mydomain.com" &&
	       substr($_SERVER['HTTP_REFERER'], 0, strlen("http://www.mydomain.com")) != "http://www.mydomain.com"
	       )
	     {
	             mysql_query("
	              INSERT INTO `log_referers` SET
	              `FromLink` = '".addslashes($_SERVER['HTTP_REFERER'])."',
	              `Link` = '".addslashes($_SERVER['REQUEST_URI'])."',
	              `IP` = '".$_SERVER['REMOTE_ADDR']."',
	              `Client` = '".addslashes($_SERVER['HTTP_USER_AGENT'])."',
	              `Entry` = NOW()
	              ");
	     }
 }

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.2
Page was generated in 0.0436 seconds