1. PHP COOKIE
PHP sends cookie in the header information of the HTTP protocol, so the setcookie () function must be called before the other information is exported to the browser, which is similar to the limit to the header () function.
1.1 sets cookie:
to set cookie with setcookie () or setrawcookie () function. It is also possible to set up the.
1.1.1 by sending the HTTP head directly to the client to set up the cookie:
bool setcookie using the setcookie () function. The value of the e variable is
expire: valid time,
path: valid directory,
domain: valid domain name, the only
secure: if the value is 1 in the top-level domain, then cookie can only be valid on the HTTPS connection, if the default value is 0 UE ='something from somewhere';
setcookie (.Quot; TestCookie.quot; $value);
setcookie. A cookie variable: setcookie ('var[a]','value'); an array is used to represent a variable, but his subscript does not use a quotation mark. So you can use $_COOKIE['var'] ['a'] to read the COOKIE variable.
1.1.2..
the parameters followed by the parameters listed above are as.
.
$value ='something from somewhere';
header (.Quot;). .quot;.Quot;.Quot; time () -1;
with header () similar to.
1.4 common problems:
slightly.
1.5 cookie working mechanism:
some learners are more impulsive and do not think about the principle, so I put it in the back.
a) server to send a cookie (multiple cookie to multiple heads) in the client by sending a HTTP Set-Cookie header with the response, and the client sends the client automatically to the server side. A HTTP cookie header, the server receives and reads the.
HTTP/1.x 200 OK
X-Powered-By: PHP/5.2.1
Set-Cookie: TestCookie=something from somewhere. Ma: no-cache
Content-type: text/html
this row implements the cookie function, and after receiving this line,
Set-Cookie: TestCookie=something from somewhere; path=/
browser will create a file on the client's disk and write in it. >/
this line is the result of using setcookie ('TestCookie','something from somewhere', '/'); the result of using header ('Set-Cookie: TestCookie=something from somewhere). For session ID's unique identifier (a long string of strings), synchronously generates some session files at the server side (you can define the session's save type themselves), and associated with the user, the.Web application stores the data associated with these session, and allows the data to pass the.
access to the site with the user between the pages. The guest will be assigned a unique identifier, the so-called session ID. It is either stored on the client's cookie or passed through the URL.
session support allows users to register any number of variables and keep them to each request. When visitors access the site, PHP automatically (if session.auto_start is set to 1) or when the user requests (session_start () call or session_register () secretly called) check whether a specific session ID is sent in the request. If so, the previously preserved environment is rebuilt. The transmission of
2.1.2 by the
2.1 sessionID is transmitted by URL session ID
slightly
2.3 uses the session function to control page caching.
in many cases, we want to determine whether our web page is cached on the client side, or to set the valid time for caching, such as some sensitive content on our web page and log in to view it, and if the cache is local, we can open the local cache directly. You can browse to the web page.
use session_cache_limiter ('private'); you can control the page client cache, you must call.
more parameters before session_start (), see http://blog.chinaunix.net/u/27731/showart.php? Id=258087 client cache control.
control client The cache time is session_cache_expire (int); the unit (s). Also to call.
before session_start (). This is just the way to control the cache in the case of session, and we can also control the cache.
2.4 in header (). Ession_destroy ();
setcookie (session_name (), '', time () -3600);
$_SESSION = array ();
.Gt; In the case of the default configuration of php5.2.1's session, when session is generated, the server will generate a predefined super global variable SID at the same time of sending header set-cookie (that is, writing cookie and throwing SID are equivalent.) when $_COOKIE['PHPSESSID'] exists, it will no longer be written to cookie and no longer generates super complete. SID, at this time, SID will be empty.
2.9 session using an instance of
[code]// to validate session's validity
function sessionVerify. VER.#91;'HTTP_USER_AGENT'.#93;);
}
elseif ($_SESSION.#91;'user_agent'.#93;! = MD5 ($_SERVER.#91;'REMOTE_ADDR'.#93;
.));} / >} / >}}