Problem with if clause and isset($_COOKIE['sid']) when passing SubID

phrench

Not yet banned
Mar 10, 2008
1,387
21
0
/dev/null
I'm trying to pass some info within subid's to the tracking platform of the network. This is where I set the cookie (in the header, before any output):

PHP:
<?php
if( !isset($_COOKIE['sid']) )
{
  $some = 'hurr';
  $dynamic = 'durr';
  $variables = 'hurr';
  $subid = base64_encode($some.",".$dynamic.",".$variables);
  setcookie("sid", $subid);
}
?>
So far no problem with this part, the cookie gets set in the browser, I verified that.
Now this is what I have in my redirect file:
PHP:
<?php  
if (isset($_COOKIE['sid'])) {
  $url = 'http://network.com/track.php?mer=54&affid=82&subid='.$_COOKIE['sid'];     
} else {
  $url = 'http://network.com/track.php?mer=54&affid=82&subid=whatever';   
}
  
header('location: '.$url);
?>
The problem is that always the "whatever" subid gets passed. Looks like the part with the isset-if-clause causes the problem. Maybe I'm blind but I really can't come up with a solution to this atm :hollering:

Any help is appreciated!
 


In PHP, for environmental variables (GET, POST, COOKIE, SERVER, etc), instead of isset() I prefer to use empty() because it usually more accurately represents what I mean (e.g. at URL index.php?a=&b=&c=true, empty($_GET['a']) === true).

That might help you, or maybe not. Good day to you, sir.
 
Is the cookie being set in the same script as the redirect, or different? Is the LP and the redirect on the EXACT same domain (even www vs. non www)?

Is your redirect in the same directory as your LP? By default, cookies set in PHP are only accessible *in the directory they were set*. To get around that you must use the path parameter in setcookie.

Code:
setcookie('sid', $subid, time() + 86400*30, '/');

The '/' part will make the cookie accessible anywhere on that domain.
 
In PHP, for environmental variables (GET, POST, COOKIE, SERVER, etc), instead of isset() I prefer to use empty() because it usually more accurately represents what I mean (e.g. at URL index.php?a=&b=&c=true, empty($_GET['a']) === true).
I learned something, thanks :)


Is the cookie being set in the same script as the redirect, or different? Is the LP and the redirect on the EXACT same domain (even www vs. non www)?

Is your redirect in the same directory as your LP? By default, cookies set in PHP are only accessible *in the directory they were set*. To get around that you must use the path parameter in setcookie.

Code:
setcookie('sid', $subid, time() + 86400*30, '/');
The '/' part will make the cookie accessible anywhere on that domain.
This helped! :bowdown:
I'm buying you a beer, pm me your paypal! :drinkup: