Problems Deleting And Resetting Cookies

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.

  1. If one of my affilates pass r_id=THEIR_CODE via url, I want to set a cookie with that r_id.

  2. 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.

  3. 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.

  4. 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.

AFAIK the $_COOKIE[‘r_id’] variable is not updaded by setting a new cookie.

the code seems to be ok. but to test it u have to reload the page before echoing it.

or may use a page, for debugging:

<pre><?php print_r($_COOKIE); ?></pre>

Sponsor our Newsletter | Privacy Policy | Terms of Service