1.session
(1) The session is stored in the server's
(2) Save one copy of each session
(3) The session has a default expiration time
(4) The session can store any type of data
Security, stress on service
Usage:
1. When a page needs to use the session, you need to add session_start () at the top of the page;
2. Operation session
Assignment $_seesion["UID"] = "";
Value $_sessino["UID"]
2.cookie
(1) Cookies are stored on the client's
(2) Each cookie is stored in one copy
(3) cookie has no default expiration time
(4) A cookie can only store strings
Unsafe, no pressure on the server
Usage:
1. Manipulating cookies
Assignment: Setcookie (key,value)
Value: $_cookie["UID"]
Usage:
Assignment value:
<?Phpsession_start ();//session start tag, write at the top. ?><!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><?php $_session["UID"] = "Zhangsan";//Assign value to $_session["UID". ?></Body></HTML>
Value:
The value can be in any page value, such as the login page, you can assign the login name, password name and other information to the $_session["UID"], the other pages on the same browser can also take the login name, password name, etc., provided that the assigned page must be opened before, if directly open other page values , you will not be able to fetch it. Then close the browser and then open, you must first open the Assignment page, the other pages to fetch the value.
<?Phpsession_start ();?><!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Body><?phpecho $_session["UID"]?></Body></HTML>
The difference between a session and a cookie