Referer Log code needed

Discussion in 'PHP' started by TheRazor5, Aug 29, 2008.

  1. #1
    Can anyone point me out or tell me how to code a referer log?

    I needed something that records the referer URL and save it into a text file somewhere in the server.

    Appreciate it,
    TheRazor
     
    TheRazor5, Aug 29, 2008 IP
  2. beacon

    beacon Peon

    Messages:
    93
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $f_name = 'ref_log.txt';
    if(isset($_SERVER[''HTTP_REFERER''])) file_put_contents($f_name,$_SERVER[''HTTP_REFERER'']."\n");
    Code (markup):
    php5+ only
     
    beacon, Aug 29, 2008 IP
  3. TheRazor5

    TheRazor5 Active Member

    Messages:
    621
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    65
    #3
    Thanks I'll try that out
     
    TheRazor5, Aug 29, 2008 IP
  4. mallorcahp

    mallorcahp Peon

    Messages:
    141
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Here's an alternative:

     
    mallorcahp, Aug 29, 2008 IP
  5. TheRazor5

    TheRazor5 Active Member

    Messages:
    621
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    65
    #5
    So any of these examples actually need a MySQL database, right?

    It's just pasting the piece of php code on the page and it's done?
     
    TheRazor5, Aug 29, 2008 IP
  6. Supah Fly

    Supah Fly Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    No.

    1. Create log file
    2. Edit the php code with your log file name
    3. If your using SmartFTP, right click on your log file and on the bottom hit properties, then edit the properties to 777, this is called chmodding.

    None of this needs a mysql database.
     
    Supah Fly, Aug 29, 2008 IP
  7. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #7
    If this is on a server where you are able to restart/reload apache, using the CustomLog directive in your sites httpd.conf is a lot more efficient.

    If you're on shared hosting, just ignore this post.
     
    joebert, Aug 29, 2008 IP
  8. TheRazor5

    TheRazor5 Active Member

    Messages:
    621
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    65
    #8
    Yeah I'm on shared hosting.
     
    TheRazor5, Aug 30, 2008 IP
  9. TheRazor5

    TheRazor5 Active Member

    Messages:
    621
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    65
    #9
    Yeah I'm on shared hosting.
     
    TheRazor5, Aug 30, 2008 IP