1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Track referrals in PHP

Discussion in 'PHP' started by hurricane_sh, Jul 25, 2004.

  1. #1
    I use the following code to track referral, it works well when user access a PHP page.
    <?php 
    $referrer = $HTTP_COOKIE_VARS["referrer"]; 
    if( $referrer == "") 
    { 
    $referrer = $HTTP_REFERER . date("Y-m-d");; 
    setcookie("referrer",$referrer, time()+60*60*24*365); 
    } 
    ?>
    PHP:
    When user downloads a file directly, I redirect the file(with .htaccess) to a php file and try to write the referral information, but get nothing, how can I track the referral for this case? Thanks!

    P.S. I asked this question in other forum, but didn't get answer. Which forum is best for PHP questions?
    SEMrush
     
    hurricane_sh, Jul 25, 2004 IP
    SEMrush
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,287
    Likes Received:
    2,600
    Best Answers:
    460
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    Do you get any sort of error when you try to write the info?
     
    digitalpoint, Jul 25, 2004 IP
  3. hurricane_sh

    hurricane_sh Well-Known Member

    Messages:
    940
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    140
    #3
    No, even didn't write a cookie with date only.

    I use this line in .htaccess for the download directory:
    Redirect permanent VocabolySetup.exe http://www.vocaboly.com/download/downfile.php?file=VocabolySetup.exe

    downfile.php
    
    <?
    	include("/include/php/cookie.php");
    	
    	header("Content-type: application/octet-stream");
    	header("Content-Disposition: attachment; filename=$file");
    	if (!readfile($file))
    ?>
    
    PHP:
    The download itself works well.
     
    hurricane_sh, Jul 25, 2004 IP
  4. nlopes

    nlopes Guest

    Messages:
    103
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    can you try something like:
    
    <?
    print_r($_SERVER);
    ?>
    
    PHP:
    then place here the output. :)
     
    nlopes, Jul 31, 2004 IP
  5. hurricane_sh

    hurricane_sh Well-Known Member

    Messages:
    940
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    140
    #5
    Many thanks, nlopes, when I trying your suggestion, I found that I made a silly mistake, the redirect didn't work in download directory(I tested in root directory and moved it later, didn't realize it could have problem).

    Now it works well in Mozilla, but doesn't work in IE, have no idea why they work different on this basic browser behavior.
     
    hurricane_sh, Aug 1, 2004 IP
  6. nlopes

    nlopes Guest

    Messages:
    103
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    uhm, please PM me and send the php file, if you want.
    I'll take a look to it and check for errors.
     
    nlopes, Aug 1, 2004 IP
  7. nlopes

    nlopes Guest

    Messages:
    103
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    MSIE has a bug handling cookies. Can you please try this?

    
    <?php 
    if(!$_COOKIE['referrer']) { 
    $referrer = $_SERVER['HTTP_REFERER'] . date("Y-m-d");
    setcookie("referrer", $referrer, time()+60*60*24*365, '/', 'vocaboly.com'); 
    } 
    ?>
    
    PHP:
     
    nlopes, Aug 2, 2004 IP
  8. hurricane_sh

    hurricane_sh Well-Known Member

    Messages:
    940
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    140
    #8
    Hi nlopes, It works now, :D :D thanks a million! ! :cool: :cool:
     
    hurricane_sh, Aug 2, 2004 IP
  9. nlopes

    nlopes Guest

    Messages:
    103
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Bah, you should read the php manual! :) Its noted there that IE has a bug that won't set cookies, if you don't set the path.

    http://php.net/setcookie
     
    nlopes, Aug 2, 2004 IP
  10. hurricane_sh

    hurricane_sh Well-Known Member

    Messages:
    940
    Likes Received:
    39
    Best Answers:
    0
    Trophy Points:
    140
    #10
    Hum, my php skill is very poor, I just search the net when I need a script, then modify it to my need, but if the script has problems, I'm in trouble :(.

    By the way, the script works well if users access normal PHP, so I thought I'm on the wrong way to track exe referrals.
     
    hurricane_sh, Aug 2, 2004 IP
  11. rajeev_seo

    rajeev_seo Peon

    Messages:
    211
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    use thats cide for trace refferals
    <?php
    $referrer = $HTTP_COOKIE_VARS["referrer"];
    if( $referrer == "")
    {
    $referrer = $HTTP_REFERER . date("Y-m-d");;
    setcookie("referrer",$referrer, time()+60*60*24*365);
    }
    ?>
     
    rajeev_seo, Apr 24, 2011 IP