Page 1 of 1
Setting cookie
Posted: Wed Mar 05, 2003 1:30 pm
by bmark
I am testing my web page with cookie setting. When I use the following code:
setcookie("cookie_user","$encuser",time()+60,"/","",0);
setcookie("cookie_session","$id",time()+60,"/","",0);
and call it from the browser that is on the the server (development machine) it works great. When I call this code from my remote desktop it does not set a cookie. I have looked at everything I can think of for the last 7 days and cannot figure out why it does not work. I am using IE 6.0 on both machines and they are setup the same way. By the way I have checked to see that the setcookie does not return a FALSE value.
CAN SOMEBODY HELP?????
the same problem
Posted: Sat Mar 15, 2003 2:10 am
by blueriver
I cant set the cookie with the following code:
setcookie("cookie", "lien", time()+3600, "/","",0);
It didnt work (server didnt sent the cookie to browser), but I wonder why its OK if I replace the above code with
setcookie("cookie", "lien", 3600, "/","",0);
whats the meaning of "3600" ? is it 3600 seconds or minutes or what ?
Whats the code if I'd like to set a cookie which expire after 1 houre from current time ?
Help me please ! Im using PHP 4.0.1p12, apache, Linux7
Posted: Sat Mar 15, 2003 3:12 am
by m3mn0n
http://www.php.net/manual/en/function.setcookie.php wrote:
boolean setcookie ( string name [, string value [, int expire [, string path [, string domain [, int secure]]]]])
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.
All the arguments except the name argument are optional. If only the name argument is present, the cookie by that name will be deleted from the remote client. You may also replace an argument with an empty string ("") in order to skip that argument. Because the expire and secure arguments are integers, they cannot be skipped with an empty string, use a zero (0) instead. The following table explains each parameter of the setcookie() function, be sure to read the
Netscape cookie specification for specifics.
For the rest see
this page.
FYI: if you are ever having problems with a specific function, in your browser type this: php.net/$function_name
$function_name would be the name of the function. in this case i used
php.net/setcookie.
