The setcookie function of PHP

time:15-05-25 forum:PHP tools and code
  http://zxianf.blog.163.com/blog/static/... 443838515/


definition and usage.

cookie is a variable sent to the browser by the server. Cookie is usually a small text file embedded in the user's computer by the server. Every time a computer requests a page through a browser, it sends the cookie. The name of

cookie is specified as a variable of the same name. For example, if the cookie being sent is called.Quot; name.quot, it will automatically create a variable called $user, which contains the value of cookie.

must assign cookie before any other output is sent. If

is successful, the function returns true, otherwise it returns false.
syntax

setcookie (name, value, expire, path, domain, secure)
parameter description is necessary. Specify the name of cookie.
value is necessary. Specify the value of cookie.
expire is optional. The period of validity of cookie is stipulated.
path is optional. The server path of the cookie is specified.
domain is optional. Specify the domain name of cookie.
secure is optional. Specifies whether cookie can be transmitted through secure HTTPS connections.
prompt and annotate

notes: you can access the value of.Quot; user.quot; user.quot; user.quot; cookie; user.quot; $HTTP_COOKIE_VARS[.quot; user.quot; or $_COOKIE[.quot; user.quot;].

note: when sending cookie, the value of cookie will be automatically encoded by URL. URL decoding is performed when receiving. If you do not need this, you can use setrawcookie () instead.

1

setting and sending cookie:

[code].lt; PHP $value =.Quot; my cookie; Ue.quot; / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / > cookie setcookie (.Quot; TestCookie.quot; $value, time () 3600*24);?.gt; [/code]

example 2
.#93; echo.Quot;.Lt; br /.gt;.Quot; echo $HTTP_COOKIE_VARS.#91;.Quot; TestCookie.quot;.#93; R />
example 3

by setting the expiration date to the date / time of the past, delete a cookie:

[code].lt;? PHP / / / / / / / / / / / / / / / / / / / / / / / / / / / / / > to set the expiration date to an hour before setcookie (.Quot; TestCookie.quot;.Quot;) - 3600); An array of cookie:

[code].lt;? PHP setcookie (.Quot; cookie.#91; three.#93;.Quot;.Quot; cookiethree.quot;); (isset ($_COOKIE.#91;.Quot; cookie.quot;.#93;)) {foreach ($_COOKIE.#91;.Quot; cookie.quot;.#93; as $name)
  • 2

prev:Comparison and analysis of JavaScript st... next:Analyze the process and principle of Dis...
post comment
Notice



approved   Ji'nan's Daming Lake scenic area is ...   Ji'nan free Scenic Area   What is the living condition of the ...   The family photo played by their par...   The universal Handbook of life in Ji...
rand   Using JSON to implement cross domain...   PHP good verification code   PHP upload file code, suitable for b...   Install.php simple production   The use of UBB in PHP
ads

other

Because all the contents of this site are reproduced from other media, the intention is to provide free services to the public, but it does not mean that this site agrees with its views, and can not be responsible for the authenticity of its verification, such as the copyright unit or individual of the manuscript does not want to publish on this site, please Contact me, I will immediately remove it, thank you. Contact: atseashawk@163.com