Log in

View Full Version : referrer kidnapped!!



davidlynch
04-16-2008, 08:47 PM
Hi,

Firstly, I'm new to Apache + php world

Having said so, let me show you my problem:

I'm trying to get the REFERRER WEBSITES that visits my site.
Most of my files are written in plain html, so I'm unable to code server side instructions.

So I put this simple javascript code:


<script type="text/javascript">
var url = "js/getreferrer.php";
var ref = document.referrer;
document.write('<script src="', url +'?ref='+ ref, '" type="text/JavaScript"><\/script>');
</script>

the getreferrer.php file just get the origin url and save it to a textfile:


<?php
$myFile = "listofreferrers.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$referrer = $_GET['ref'];
$stringData = "$referrer\n";
fwrite($fh, $stringData);
fclose($fh);
?>

The result is that EVERY referrer url entry is replaced with the full URL of the page that uses de javascript code,

In english - if I visit my page called "http://site/file1.htm" from a search result on search engine "http://searchengine", my referrer recorded is "http://site/file1.htm" instead of "http://searchengine".

When I use PHP this problem doesn't arise, but I'm unable to use any other format than "html" file

Any help will be highly appreciatted

David

thetestingsite
04-16-2008, 10:30 PM
When I use PHP this problem doesn't arise, but I'm unable to use any other format than "html" file


Why exactly can't you use php? It seems as if you are using it when you are calling the javascript function that you posted:



<script type="text/javascript">
var url = "js/getreferrer.php";
var ref = document.referrer;
document.write('<script src="', url +'?ref='+ ref, '" type="text/JavaScript"><\/script>');
</script>


so why can't you just use the php code on the main page (after you change the extension on the file from .html to .php of course)?