<?php
@error_reporting(0);
@ini_set('display_errors',0);
function getIP($remoteAddress)
{
if(empty($remoteAddress))
return;
$regex='/^([^.]+\.[^.]+\.[^.]+\.).*/';
if(preg_match($regex,$remoteAddress,$matches))
return$matches[1].'0';
else
return;
}
function getVisitorId($guid,$account,$userAgent,$cookie)
{
if(!empty($cookie))
return$cookie;
$message='';
if(!empty($guid))
$message=$guid.$account;
else
$message=$userAgent.uniqid(getRandomNumber(),true);
return'0x'.mb_substr(md5($message),0,16);
}
function getRandomNumber()
{
return rand(0,0x7fffffff);
}
function writeGifData()
{
header('Content-Type: image/gif');
header('Last-Modified: '.gmdate('D, d M Y H:i:s T'));
header('Cache-Control: no-store,no-cache,must-revalidate,max-age=0,post-check=0,pre-check=0');
header('Expires: -1');
echo join([chr(0x47),chr(0x49),chr(0x46),chr(0x38),chr(0x39),chr(0x61),chr(0x01),chr(0x00),chr(0x01),chr(0x00),chr(0x80),chr(0xff),chr(0x00),chr(0xff),chr(0xff),chr(0xff),chr(0x00),chr(0x00),chr(0x00),chr(0x2c),chr(0x00),chr(0x00),chr(0x00),chr(0x00),chr(0x01),chr(0x00),chr(0x01),chr(0x00),chr(0x00),chr(0x02),chr(0x02),chr(0x44),chr(0x01),chr(0x00),chr(0x3b)]);
}
function sendRequestToGoogleAnalytics($utmUrl)
{
$options = array('http'=>array('method'=>'GET','user_agent'=>$_SERVER['HTTP_USER_AGENT'],'header'=>('Accept-Language: '.$_SERVER['HTTP_ACCEPT_LANGUAGE'])));
if(!empty($_GET['utmdebug']))
$data=file_get_contents($utmUrl,false,stream_context_create($options));
else
$data=@file_get_contents($utmUrl,false,stream_context_create($options));
}
function trackPageView()
{
$timeStamp=$_SERVER['REQUEST_TIME'];
$domainName=$_SERVER['SERVER_NAME'];
if(empty($domainName))
$domainName='';
$documentReferer=$_GET['utmr'];
if(empty($documentReferer)&&$documentReferer!=='0')
$documentReferer='-';
else
$documentReferer=urldecode($documentReferer);
$documentPath=$_GET['utmp'];
if(empty($documentPath))
$documentPath='';
else
$documentPath=urldecode($documentPath);
$account=$_GET['utmac'];
$userAgent=$_SERVER['HTTP_USER_AGENT'];
if(empty($userAgent))
$userAgent='';
$cookie=$_COOKIE['__utmmobile'];
$guidHeader=$_SERVER['HTTP_X_DCMGUID'];
if(empty($guidHeader))
$guidHeader=$_SERVER['HTTP_X_UP_SUBNO'];
if(empty($guidHeader))
$guidHeader=$_SERVER['HTTP_X_JPHONE_UID'];
if(empty($guidHeader))
$guidHeader=$_SERVER['HTTP_X_EM_UID'];
$visitorId=getVisitorId($guidHeader,$account,$userAgent,$cookie);
setrawcookie('__utmmobile',$visitorId,$timeStamp+63072000,'/');
$utmGifLocation='http://google-analytics.com/__utm.gif';
$utmUrl=$utmGifLocation.'?utmwv=4.4sh&utmn='.getRandomNumber().'&utmhn='.urlencode($domainName).'&utmr='.urlencode($documentReferer).'&utmp='.urlencode($documentPath).'&utmac='.$account.'&utmcc=__utma%3D999.999.999.999.999.1%3B&utmvid='.$visitorId.'&utmip='.getIP($_SERVER['REMOTE_ADDR']);
sendRequestToGoogleAnalytics($utmUrl);
if(!empty($_GET['utmdebug']))
header('X-GA-MOBILE-URL: '.$utmUrl);
writeGifData();
}
trackPageView();