Why the function setcookie() is not working for me

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
User avatar
rax369
Forum Commoner
Posts: 56
Joined: Sun Oct 06, 2002 8:50 pm

Why the function setcookie() is not working for me

Post by rax369 »

I was wishing to experiment the handling of cookies, but because my script doesnt want to understand this simple command:

Code: Select all

<?php
setcookie("test_cookie", "some_value");

?>
I have not been able to deal w/cookies, could u tell me please, what I'm doing wrong. :cry:

I followed some examples given in a php book('
ySQL/PHP Database Applications'), and others show in the official php page (http://www.php.net/manual/en/function.setcookie.php), about the setcookie() function, but none worked for me.

I used the function before every command in my php, as is explained in the official documentation page:
setcookie() defines a cookie to be sent along with the rest of the HTTP headers. Like other headers, cookies must be sent before any output from your script (this is a protocol restriction). This requires that you place calls to this function prior to any output, including <html> and <head> tags as well as any whitespace. If output exists prior to calling this function, setcookie() will fail and return FALSE. If setcookie() successfully runs, it will return TRUE. This does not indicate whether the user accepted the cookie.
... but not even using it like that worked at all. :x

HELP PLEASE :!:
User avatar
rax369
Forum Commoner
Posts: 56
Joined: Sun Oct 06, 2002 8:50 pm

Post by rax369 »

forget about what I said, now I'm been able to use, this function.

Now my only problem is that I'm not seen the cookie in my temporary internet files folder. How could I be able to see the cookie 'appears' :?:

thx :wink:
User avatar
BigE
Site Admin
Posts: 139
Joined: Fri Apr 19, 2002 9:49 am
Location: Missouri, USA
Contact:

Post by BigE »

one thing when using the setcookie() function, its always a good idea to set a time limit, and aa path/url with the cookie. Sometimes it just helps. To get data from a cookie in php, use this code

Code: Select all

&lt;?php
//PHP 4.1.0 and greater
echo $_COOKIE&#1111;'test_cookie'];
//Everything below 4.1.0
echo $HTTP_COOKIE_VARS&#1111;'test_cookie'];
?&gt;
Hope that helps.
Post Reply