Results 1 to 2 of 2

Thread: referrer kidnapped!!

  1. #1
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question referrer kidnapped!!

    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

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Quote Originally Posted by davidlynch View Post
    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:

    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>
    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)?
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •