Enable cookies chrome wordpress hướng dẫn
(PHP 4, PHP 5, PHP 7, PHP 8) setcookie — Send a cookie Descriptionsetcookie( setcookie(string
Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE array. Cookie values may also exist in $_REQUEST. Parameters» RFC 6265 provides the normative reference on how each setcookie() parameter is interpreted. name The name of the cookie. value The value of the
cookie. This value is stored on the clients computer; do not store sensitive information. Assuming the expires_or_options The time the cookie expires. This is a Unix timestamp so is in number of seconds since the epoch. One way to set this is by adding the number of seconds before the cookie should expire
to the result of calling time(). For instance,
path The path on the server in which the cookie will be available on. If set to domain The (sub)domain that the cookie is available to. Setting this to a subdomain (such as Older browsers still implementing the deprecated
» RFC 2109 may require a leading secure Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client. When set to httponly When options An associative array which may have any of the keys Return Values If output exists prior to calling this function, setcookie() will fail and return Changelog
ExamplesSome examples follow how to send cookies: Example #1 setcookie() send example
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. If you don't want this, you can use setrawcookie() instead. To see the contents of our test cookie in a script, simply use one of the following examples:
Example #2 setcookie() delete example When deleting a cookie you should assure that the expiration date is in the past, to trigger the removal mechanism in your browser. Examples follow how to delete cookies sent in previous example:
Example #3 setcookie() and arrays You may also set array cookies by using array notation in the cookie name. This has the effect of setting as many cookies as you have array elements, but when the cookie is received by your script, the values are all placed in an array with the cookie's name:
The above example will output: three : cookiethree two : cookietwo one : cookieone
Notes
Common Pitfalls:
Multiple calls to setcookie() are performed in the order called. See Also
walterquez ¶ 10 years ago
Bachsau ¶ 10 years ago
Anonymous ¶ 2 years ago
paul nospam AT nospam sitepoint dot com ¶ 15 years ago
nacho at casinelli dot com ¶ 5 years ago
gabe at fijiwebdesign dot com ¶ 15 years ago
Anonymous ¶ 15 years ago
= ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false;
MrXCol ¶ 11 years ago
byz ¶ 6 years ago
bluewaterbob ¶ 15 years ago
user at example.com ¶ 2 years ago
lferro9000 at gmail dot com ¶ 5 years ago
ellert at vankoperen dot nl ¶ 8 years ago
gareth at gw126 dot com ¶ 16 years ago
dmitry dot koterov at gmail dot com ¶ 7 years ago
Eric ¶ 12 years ago
clearpieces( $inKey , $inFirst ) {
ahmetantmen at msn dot com ¶ 15 years ago
= '--'; hansel at gretel dot com ¶ 15 years ago
Anonymous ¶ 12 years ago
Anonymous ¶ 2 years ago
stovenator at gmail dot com ¶ 15 years ago
jdknock (at) gMaIl (dot) com ¶ 11 years ago
jay at w3prodigy dot com ¶ 12 years ago
mkmohsinali at gmail dot com ¶ 11 years ago
#in case user has come for first time and cookies are not set then Anonymous ¶ 1 year ago
Carl V ¶ 17 years ago
cwillard at fastmail dot fm ¶ 15 years ago
break_cookie ($cookie_string) { jonathan dot bergeron at rve dot ulaval dot ca ¶ 15 years ago
chris at styl dot ee ¶ 11 years ago
laffen ¶ 13 years ago
isooik at gmail-antispam dot com ¶ 14 years ago
$domain) )
bocian941 at pawno dot pl ¶ 11 years ago
RemoveCookieLive($name)
J?rg Aldinger ¶ 19 years ago
Anonymous ¶ 3 years ago
|