Hi,
I am having trouble managing cookies in php, could someone please have a look and sort this out or suggest a better way to do it.
I want to save an ID in the cookie on my site for 30 days. The Id comes in the URL when the user clicks the advert of my site displayed on an affiliate site. The problem is, If the user comes back on the site through a different affiliate and bring a different ID then the previous cookies should be deleted and a new cookie should be placed for 30 days again.
I can set the first cookie but i'm not able to delete it and place a new one. please see the code below
//set a 30 days cookie.
//if the user's comming from different affiliate then overwrite the existing cookie
if(isset($_GET['uid'])){
if(!isset($_COOKIE['aff_uid']) or $_COOKIE['aff_uid']<>$_GET['uid']){
$hostname = $_SERVER['HTTP_HOST'];
setcookie("aff_uid", "", time()-3600,"/", "$hostname");
$cookie_life = time() + 2592000; //30 days
setcookie("aff_uid", $_GET['uid'], $cookie_life,"/", "$hostname");
}
}
when i display the cookie value on a different page it always shows me the old value.
Many Thanks,
Zeeshan.