How to Create a Cookie
The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE the tag.
Syntax
setcookie(name, value, expire, path, domain);
Example
The following example sets a cookie named "uname" - that expires after ten hours.
setcookie("uname", $name, time()+36000);
?>
A cookie was set on this page! The cookie will be active when the client has sent the cookie back to the server.
---------------------------------------------------------------------
How to Retrieve a Cookie Value
When a cookie is set, PHP uses the cookie name as a variable.
To access a cookie you just refer to the cookie name as a variable.
Tip: Use the isset() function to find out if a cookie has been set.
Example
The following example tests if the uname cookie has been set, and prints an appropriate message.
The setcookie() function is used to create cookies.
Note: The setcookie() function must appear BEFORE the tag.
Syntax
setcookie(name, value, expire, path, domain);
Example
The following example sets a cookie named "uname" - that expires after ten hours.
setcookie("uname", $name, time()+36000);
?>
A cookie was set on this page! The cookie will be active when the client has sent the cookie back to the server.
---------------------------------------------------------------------
How to Retrieve a Cookie Value
When a cookie is set, PHP uses the cookie name as a variable.
To access a cookie you just refer to the cookie name as a variable.
Tip: Use the isset() function to find out if a cookie has been set.
Example
The following example tests if the uname cookie has been set, and prints an appropriate message.
No comments:
Post a Comment