PHP3 Manual | ||
---|---|---|
Prev | Next |
setcookie -- Send a cookie
SetCookie() defines a cookie to be sent along with the rest of the header information. 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 any argument with an empty string ("") in order to skip that argument. The expire and secure arguments are integers and cannot be skipped with an empty string. Use a zero (0) instead. The expire argument is a regular Unix time integer as returned by the time() or mktime() functions. The secure indicates that the cookie should only be transmitted over a secure HTTPS connection. Some examples follow:
Example 1. SetCookie examples SetCookie("TestCookie","Test Value"); SetCookie("TestCookie",$value,time()+3600); /* expire in 1 hour */ SetCookie("TestCookie",$value,time()+3600,"/~rasmus/",".utoronto.ca",1); |
Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name. ie. to see the contents of our test cookie in a script, simply do:
echo $TestCookie;
For more information on cookies, see Netscape's cookie specification at http://www.netscape.com/newsref/std/cookie_spec.html.
Prev | Home | Next |
header | Up | Image functions |