Page 1 of 1

can't set cookie????

Posted: Wed Nov 12, 2003 2:20 pm
by i like chips
OK i've been going at this for hours now and I can't figure out what the problem is. I just want to set a cookie dammit!! hehe ok here's some code:

I have a cookie.php:

Code: Select all

<?php
$value = 'something from somewhere';

setcookie("testcookie", $value, time()+3600, '/');
?>

I have the cookie.php stored under http://blahblah.com/cookie.php
I manually type that address in and after that I go back to http://blahblah.com. This SHOULD work right??

But the cookie's not being set!! I've checked the temporary internet files and no cookie! :( What am I doing wrong? Some help would be appreciated!



Posted: Wed Nov 12, 2003 3:45 pm
by Johnm
Let's eliminate the simple things first, are cookies enabled on you browser? Secondly, what do youget if you add...

Code: Select all

<?php
$value = 'something from somewhere'; 

setcookie("testcookie", $value, time()+3600, '/'); 
echo $HTTP_COOKIE_VARS["testcookie"];



?>
John M

Another simple pointer

Posted: Thu Nov 13, 2003 12:19 pm
by php_passerby
I had a lot of troubles when I began using cookies because I got the message like "Headers already sent". Those error messages were caused by a space in the php script sent before the opening php brace "<?php". (blank lines will have the same effect)

To create a cookie, it has to be sent before any html output!

Could this be the kind of problem you are suffering?

Cookies and Norton

Posted: Thu Nov 13, 2003 2:38 pm
by smcpoland
Have you turned off Privacy checking in Norton - I found when trying this the cookie was stopped by the Internet Security package - may also be true for McAfee -

You have to look at the logs.....