Location: PHPKode > scripts > webstat > webstat/Tracker.php
<?php

/*----------------------------------------------------------------------------------------------------------------------
                     Use this code on the website which traffic u want to track 
         <script type="text/javascript" src="http://yourdomain.com/Tracker.php?mode=js&id=1234"></script>
       <noscript><img src="http://yourdomain.com/NTracker.php?id=1234" border="0" alt="" width="1" height="1"></noscript>
-------------------------------------------------------------------------------------------------------------------------*/


/*============================================================================================
                        This class is developed by Md. Mahabubur Rahman
                        For more information contact with me  [hide@address.com]
                        THANKS ALL FOR USING THIS CLASS
==============================================================================================*/


include('database.php');
include('userall.php');

class Tracker {
	
	
	
	var $mode;
	var $id;
	var $resulation;
	
	// domain which traffic u want to track
	var $trafficdomain = "domainname.com";
	
	
	/* Class Constructor */
	function Tracker(){
		$this->mode  =  $_GET['mode'];  // if java script supported
		$this->id   =   $_GET['id'];   // Get the web id
				
		// Check if mode is js and and id not null
		if($this->mode!='' && trim($this->mode=="js") && $this->id!=''){
			// Check if the site is registered
			 $this->GetTrack();
			}
		
		// Check if the script called second time time to get all information		
		if($this->mode=='' && $_GET["js_url"]){
			$this->GetAllInfo();
		}
		}
	
	
		
	function GetTrack(){
		$orgdomain=$this->GetDomain($_SERVER[ "HTTP_REFERER" ]);
		if($orgdomain=='') exit;
		if(eregi($orgdomain,$this->trafficdomain)){
		 $this->PrintJavaScript();
		 //return true;
		} else exit;
		
	}
	
	
	
	/* Send javaScript and Get user all information */
	function PrintJavaScript(){
		header("content-type: text/javascript"); // send javascript to browser
        echo "f='' + escape(top.document.referrer);";
        echo "function getCookie(c_name)\n";
        echo "{\n";
        echo "if (document.cookie.length>0)\n";
        echo "{\n";
        echo "c_start=document.cookie.indexOf(c_name + \"=\");\n";
        echo "if (c_start!=-1)\n";
        echo "{\n ";
        echo "c_start=c_start + c_name.length+1;\n ";
        echo "c_end=document.cookie.indexOf(\";\",c_start);\n";
        echo "if (c_end==-1) c_end=document.cookie.length;\n";
        echo "return unescape(document.cookie.substring(c_start,c_end));\n";
        echo "}\n"; 
        echo "}\n";
        echo "return \"\";\n";
        echo "}\n";
        echo "function setCookie(c_name,value,expiredays)\n";
        echo "{\n";
        echo "var exdate=new Date();\n";
        echo "exdate.setTime(exdate.getTime()+expiredays);\n";
        echo "document.cookie=c_name+ \"=\" +escape(value)+\n";
        echo "((expiredays==null) ? \"\" : \";expires=\"+exdate.toGMTString());\n";
        echo "}\n";
        echo "function checkCookie()\n";
        echo "{\n";
        echo "username=getCookie('username');\n";
        echo "if (username!=null && username!=\"\")\n";
        echo "{\n";
        echo "var G=\"enable\";";
        echo "}\n";
        echo "else\n";
        echo "{\n";
        echo "setCookie('username',\"Mahabub\",1000*60*60*24);";
	    echo "var G=\"disable\";";
        echo "}\n";
        echo "return G;\n";
        echo "}\n";
        echo "var l=checkCookie()\n";
        echo "\nw=screen.width;\nh=screen.height;\nv=navigator.appName;\n";
        echo "if (v != 'Netscape') {var c=screen.colorDepth;}\nelse {var c=screen.pixelDepth;}\n";
        // Edit here 
        echo 'jsinfo = "http://yourdomain.com/Tracker.php?js_resolution=" + w + "x" + h + "&js_referer=" + f + "&cookie=" + l + "&js_color=" + c + "&js_url=" + escape(document.URL);';
        echo "\ntry {\nvar script = document.createElementNS('http://www.w3.org/1999/xhtml','script');\n";
        echo "script.setAttribute('type', 'text/javascript');\n";
        echo "script.setAttribute('src', jsinfo);\n";
        echo "document.getElementsByTagName('body')[0].appendChild(script);\n";
        echo "}\ncatch(e) {\n";
        echo 'str = "<script type=\"text/javascript\" src=\""+jsinfo+"\"></script>"';
        echo "\n".'document.write(str+""); }';
	 }
	
	
	
	function GetAllInfo(){
		global $MySql;
		global $userall;
		
		
		/* value From JavaScript */
		$js_resolution = addslashes ( str_replace ( "|" , "" , strip_tags ( $_GET [ "js_resolution" ] ) ) );
		$js_color      = addslashes ( str_replace ( "|" , "" , strip_tags ( $_GET [ "js_color"      ] ) ) );
        $js_referer    = addslashes ( str_replace ( "|" , "" , strip_tags ( $_GET [ "js_referer"    ] ) ) );
        $js_url        = addslashes ( str_replace ( "|" , "" , strip_tags ( $_GET [ "js_url"        ] ) ) );      
		
		
		
		
		
        
        /* Get User Information */
        $UserAgent  =  $_SERVER['HTTP_USER_AGENT'];
        $UserIp     =  $_SERVER['REMOTE_ADDR'];
        
        
        // get the id of the tracked domain
        $webid      = $this->id;  
         
       
        
        
			
        	/* Operating System */
        	$Operating_System     =   $userall->operating_system_detection($UserAgent);
			$Operating_System     =   $userall->kill_special_chars($Operating_System);
			$Operating_System     =   $userall->kill_special_chars_track($Operating_System);
			
			/* Browser */
			$Browser              =   $userall->browser_detection($UserAgent);
			$Browser              =   $userall->kill_special_chars($Browser);
			$Browser              =   $userall->kill_special_chars_track($Browser);
			
			
			/* Resulation */
			$Resulation          =  $js_resolution;
			
			/* Color */
			$Color               =  $js_color;
			
			
			
			/* refrer information */
			$ReferInformation    =  $userall->seReferer($js_referer);
			if(empty($ReferInformation)){
				$referurl       =  $js_referer;
			}
			else {
				$referurl       =  $ReferInformation['Referer'];
				
				$searchkey      =  $ReferInformation['Query'];
				$searchkey      =  $userall->kill_special_chars($searchkey);
				$searchkey      =  $userall->kill_special_chars_track($searchkey);
				
				
				$SearchEngine   =  $ReferInformation['Se'];
			}
		
			
			
			
			// if the cookie is disable [Cookie is set for 24 hours]
			
           if($_GET['cookie']=='disable'){
           $VisitorID  =  $MySql->InsertVisitor($webid,"1");
           
           if($VisitorID!=''){
           	 $MySql->InsertCountry($VisitorID,$UserIp,$webid);
           	 $MySql->InsertCOLOR($VisitorID,$webid,$Color,$Resulation);
           	 $MySql->InsertAdditionalDetail($VisitorID,$webid,$Operating_System,$Browser);
           	 $MySql->InsertRefer($VisitorID,$webid,$referurl,$searchkey,$SearchEngine);
           }
           }
           
           
          // if cookie is enable  
          else {
          	$MySql->InsertReload($webid,"1");
          }
        
       // }
	}
	
	
	
	function GetDomain($url){
		if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) === FALSE)
        {
        return false;
        }
        $parts = parse_url($url);
        $domain=trim(str_replace("www.","",$parts['host']));
        return $domain;
	}
	
}

$Tracker = new Tracker();

?>
Return current item: webstat