i got an issue with cookies and i can solve it...
I've read some tutorials, but i still cant create a cookie...
Well... I am trying to create a referrer system, it will provide a link to my users with a &id=number at the end. (this number will be related to their account, so i can identify and give them a reward later).
I've tried many ways, like:
setcookie('ref', $c_value, time()+86400, '.mydomain.com', '/');
setcookie('ref', $c_value, time()+86400, '/', '.mydomain.com');
setcookie('ref', 'test', time()+86400, '/', '.mydomain.com');
setcookie('ref', 'test', time()+86400, '/', '.mydomain.com');
setcookie('ref', 'test', time()+86400, '/', 'www.mydomain.com');
$time = time()+86400; setcookie('ref', 'test', '$time', '/', 'www.mydomain.com/');
PS: I've tryied all separately.
But none of them seems to work, do i have to turn on some feature on php.ini?
Im trying to implement this code to:
if(!empty($_GET['id'])){
$c_value = $_GET['id'];
setcookie('ref', $c_value, time()+86400, '/', '.mydomain.com');
}
I have also tried without the $_GET function, but no matter what i do, it doesnt work...
PS2: I am using google analytics and facebook plugins that also create cookies, do they interfer in something? And i am also using SESSIONID.
setcookie
works by sending an HTTP header before the response body. All functions that send headers (e.g. setcookie
, session_start
, and header
) have to be called before you output anything in the body.
So either move the setcookie()
function earlier in your script, or use the output buffering functions to buffer the output until after you call it.