I want to make a affiliate program just like cj.com.
I use cookies to track leads and sales from affiliates but failed.
here is what I have done:
We have site A:www.a.com and site B:ww.b.com
a1.php of site A:
<?
$timestamp=time();
$cookietime = $timestamp+36000;
$user="new";
setcookie('ckuser',$user,$cookietime);
?>
a2.php of site B:
<?
$userid=$HTTP_COOKIE_VARS['ckuser'];
$testrecordfile='test_record.txt';
$test_record="userid=$userid\n";
writefile($testrecordfile,$test_record,"ab");
//echo $test_record;
function writefile($filename,$data,$method="rb+",$iflock=1){
touch($filename);
$handle=fopen($filename,$method);
if($iflock){
flock($handle,LOCK_EX);
}
fputs($handle,$data);
if($method=="rb+") ftruncate($handle,strlen($data));
fclose($handle);
}
?>
test.html of site B:
<img src=http://www.a.com/a2.php>
When I open test.html on site B, I got userid=NULL in
'test_record.txt' .
Why can't I use cookie to track user? Anyone have good idea of tracking sales or leads of affiliates on merchant's site?
Thanks.