I would like to create a simple web statistics javascript code ( analytics )
but wondering whats the correct way to include referer ?
I think somehow need to implement javascript escape(document.referrer) with php inside track.php
This is what i have so far :
script on remote site:
<script type="text/javascript" src="http://www.mydomain.com/track.php"></script>
local track.php:
<?php
$str = 'document.write(\'<img src="http://www.mydomain.com/tracking.php?id="/>\');';
echo $str;
?>
local tracking.php
<?php
header("content-type:image/gif");
$ip = $_SERVER["REMOTE_ADDR"];
$browser = $_SERVER['HTTP_USER_AGENT'];
//$referer = ????
///etc...
// save results to db ...
You want to build a list of all params, for example…
…then you need to serialise them to GET params…
…then make a request…
The params you send should be stuff only JavaScript can get, such as resolution etc. Sending them via the GET params of an image allows you to bypass Same Origin Policy.
Additionally, the image request can get information such as the IP, Referrer, etc. Examine the
$_SERVERsuper global for a wealth of information about the request.