My Code So Far.
<?php if(!empty($_REQUEST['r_id']) AND !empty($_COOKIE['r_id'])) { if($_REQUEST['r_id'] == $_COOKIE['r_id']) { setcookie('r_id', '', 1, '/', '.mydomain.com', 0); setcookie('r_id', $_REQUEST['r_id'], time()+604800, '/', '.mydomain.com', 0); } elseif($_REQUEST['r_id'] != $_COOKIE['r_id']) { setcookie('r_id', '', 1, '/', '.mydomain.com', 0); setcookie('r_id', $_REQUEST['r_id'], time()+604800, '/', '.mydomain.com', 0); } } elseif(!empty($_REQUEST['r_id']) AND empty($_COOKIE['r_id'])) { setcookie('r_id', $_REQUEST['r_id'], time()+604800, '/', '.mydomain.com', 0); } ?>Hello, I am trying to update our affiliate program so that the refering urls can be easily spidered. I decided that cookies are the best way to achieve this.
Here is what I am trying to do.
-
If one of my affilates pass r_id=THEIR_CODE via url, I want to set a cookie with that r_id.
-
My cookies are set for 7 days, so that if no one else refers the same customer to my site, they still get credit for the sale if it is a returning customer.
-
Now if the same customer is already cookied from the same affiliate, and returns via his referal, I want to reset the current cookies time back to 7 days. Resetting the clock.
-
Now if another one of my affilates sends me a customer that was previously refered by another and if the old cookie is still valid, I want to delete the old one and then send a new cookie with the new affilates information.
i understand the whole if and else statement but, I do not think I am doing something correct with setcookie(). Everytime I try to delete the cookie and reset it, and echo $_COOKIE[‘r_id’] I keep getting the old information.
Please Help.