Jump to content

Problems With Deleting And Setting Cookies


scwebmaster

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.