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?
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.
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.
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:
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
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.
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); } ?>