Jump to content

Simple Cookie question


amac4all

Recommended Posts

Here's my cookie code:

 

$offer = $_GET['AID'];
$AdID = $_GET['Adwords'];
$kw = $_GET['kw'];
$combine = $AdID."-".$kw;

$Month = 2592000 + time();

if (isset($AdID)) {
setcookie(PPC,$combine,$Month);
}
if ($offer == 2) {
setcookie(OFFER,2,$Month);
}
if ($offer == 1) {
setcookie(OFFER,1,$Month);
}

 

I'm basically doing A/B testing on my site with 2 different ads. When someone comes to my OFFER B landing page, I assign them a tracking cookie, then I read the cookie and present them the same offer again and again as they load other pages on the site. This ensures that they don't see my OFFER A, which is presented to regular non PPC visitors.

At any rate, when someone lands on my landing page I GET the AID identifier and set it in the cookie. Unfortunately, when the visitor clicks on a second page, the cookie is removed and no longer exists. I can't find a reason for this. Any thoughts?

Link to comment
Share on other sites

Are PPC and OFFER defined somewhere as strings?

 

The amount of code you've posted isn't much help in trying to solve your problem. Can you post the code where you check the cookies?

 

I'm guessing PHP is assuming PPC and OFFER are strings (if they aren't defined), and converting the ints to strings, so the cookies should get set. All the logic here looks fine assuming the URL contains the correct variables.

 

Your issue is likely to be elsewhere in your code.

Link to comment
Share on other sites

I may be giving away my newbie status here. This is all the code I'm using to set the cookies. (I thought the PPC cookie was working fine before I started this project). I use other code to switch out the jpg offers like this:

 

if ($_COOKIE['OFFER'] == 2) { echo '<img class="alignnone size-full wp-image-565" alt="" src="/offerb.gif" width="280" height="90" />';} else { echo '<img class="alignnone size-full wp-image-565" alt="ocpad" src="/specialoffer.gif" width="280" height="90" />';}

 

This code is being used on a wordpress site if that helps.

Link to comment
Share on other sites

Put quotes around OFFER and PPC. That isn't what the problem is, but those lines are throwing warnings. You will also get one when if ANY of your GET variables aren't set. You should check for those.

 

I think the problem is with how your variables are arriving, not with the code or logic. Try printing out your variables before you do your logic to make sure they are what you expect:

echo $_GET['AID'].'<br/>';
echo $_GET['Adwords'].'<br/>';
echo $_GET['kw'].'<br/>';
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.