How to create a referral link?

Discussion in 'PHP' started by anyways, Sep 2, 2009.

  1. #1
    Hi

    I'm about to buy an AD spot on a website, but I want to know how many clicks that specific AD will bring to my site.

    I'm not sure how to create a referral link and what service to use to count the clicks.

    My idea was to create a random php page on my server and make it redirect to my homepage but at the same time having a google analytic script in it to be able to count the clicks. However it appears that you cannot have any other variables if you want to redirect a php page to another. So I'm not quite sure what to do anymore...

    Any help would be appreciated.
     
    anyways, Sep 2, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    In your redirection page, just set up a cookie with the referral id / referring URL. Then on your target page you can add it to google analytics via a js call.
     
    premiumscripts, Sep 2, 2009 IP
  3. shaunole

    shaunole Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't quite understand why you aren't able to use variables then redirect. You should be able to render all of the php you need, then redirect assuming you have not output html.

    With that in mind, you should be able to store the referrer, ip, and/or whatever other information you want to the database before the header redirect.

    The reason you cannot output to the browser before you redirect has to do with HTML headers. They include all of the processing instructions for the browser (content-type, HTML Status code, etc). These instructions must be sent before any content is sent to the browser. Once they are sent, you cannot amend or resend the headers. Therefor, no redirect.

    If you have a need to redirect after the page headers are sent, I would suggest looking into output buffering or using javascript.

    Hopefully this helps.
     
    shaunole, Sep 3, 2009 IP