can't set cookie????

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
i like chips
Forum Newbie
Posts: 1
Joined: Wed Nov 12, 2003 2:20 pm

can't set cookie????

Post 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!


User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post 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
User avatar
php_passerby
Forum Newbie
Posts: 6
Joined: Fri Oct 03, 2003 9:41 am
Location: El Salvador

Another simple pointer

Post 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?
smcpoland
Forum Newbie
Posts: 4
Joined: Wed Nov 05, 2003 8:31 am
Contact:

Cookies and Norton

Post 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.....
Post Reply