Page 1 of 1

Why the function setcookie() is not working for me

Posted: Tue Nov 26, 2002 10:15 pm
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 :!:

Posted: Tue Nov 26, 2002 11:02 pm
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:

Posted: Wed Nov 27, 2002 12:21 am
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.