SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple log visitor referrer script?

    I've been trying to find a simple script that logs the referrer urls of visitors but am not having much luck. Does somebody know where I can get one or perhaps even be able to put together a simple script that logs the referrer urls into a .txt file?

    I would be forever in your debt.

  2. #2
    SitePoint Evangelist bronze trophy
    Join Date
    Feb 2013
    Posts
    511
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Using session to make sure only the first hit on this script gets logged. session_start() will need to be at the top of your page.
    PHP Code:
    <?php
    session_start
    ();

    $file "referrers.txt"

    if (isset(
    $_SERVER['HTTP_REFERER'])){ 
        
    $referer parse_url ($_SERVER['HTTP_REFERER']); 
        
    $ReferingSite $referer['host'];
        if (!isset(
    $_SESSION['referer']) && !empty($ReferingSite)){
            
    $_SESSION['referer'] = "set";
            
    $Add_Referrer "$ReferingSite\r\n"
            
    $fp fopen($file"a") or die("Couldn't open $file for writing!");
            
    fwrite($fp$Add_Referrer) or die("Couldn't write values to file!"); 
            
    fclose($fp);
        }

    ?>

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you thank you thank you!


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
  •