1 //Understanding Cookies: A mechanism for storing data to track users and identify users in a customer-service browser2 //In a nutshell, a cookie is a file that the Web server temporarily stores on the user's hard drive and is then read by the Web browser, and when the user sends the Web site again, the specific information is recorded by reading the cookie file, which quickly makes the corresponding , the user does not need to enter the user's ID and password to directly log in to the site cookie function: 1. Certain information that is recorded by the person 2. Pass the variable 3 between pages. Storing the page you are viewing in a cookie Temp folder can improve the speed of future browsing3 4 5 6 //Create Cookies7 //bool Setcookie (string name[,string value[,int expire[,string path[,string domain[,int secure] []])8 The variable name of the//name cookie is called by $_cookie["CookieName" to invoke a cookie with the variable named CookieName.9 //value The value of a COOKIE variable that is stored on the client and cannot be used to hold sensitive data can be obtained by $_cookie[' values 'Ten //expire The expiration time of the cookie One //path The valid path of the cookie on the server side A //domain A valid domain name for cookies - //secure Indicates whether the cookie is near the safe https value of 0 or 1 - the Setcookie("TestCookie", ' www.baidu.com '); - Setcookie("TestCookie", Time() +60); - - //ways to read cookies + //Detect if cookie file exists, if no settings exist - if(!Empty($_cookie[' TestCookie ']) { + Setcookie(' MyCookie ',Date(' y-m-d h:i:s ')); A}Else{ at //If there is a save expiration time - Setcookie(' MyCookie ',Date(' y-m-d h:i:s '), Time() +60); - Echo $_cookie[' MyCookie '].Date("Y-m-d h:i:s"); - } - //Delete Cookies - Setcookie(' MyCookie ', Time()-1); in - //Cookie Declaration Period to //If the cookie expiration time is not set, his life cycle disappears as the browser shuts down. This cookie, known as a session cookie, is typically not exploded on the hard disk, but is stored in memory. + //browser can support up to 300 cookie files, each file size 4KB, the United States domain name up to 20 cookies, if the arrival period will be automatically deleted. - the * //session Understand $ //session is the time interval that only one end user communicates with an interactive system, from the time it takes to register to enter the system and log out of the system. Panax Notoginseng //principle: When the session is started, it randomly generates a unique session_id that is the name of the session, and session_id exists in the server's memory. When the page is closed, this ID will be automatically logged out and re-logged on to this page and will be generated again. - //function: Check with information, convenient user next login. the + //Initiate a reply, register a session, use a session, delete a session A //Create a session in two ways: 1 session_start (); 2 Session_register () This will start the session in a stealth manner. the //Register creation session: Required at php.ini register_globals instruction set to: on + - Session_Start(); $ $_session[' admin '] =NULL;//declares a variable named admin, and assigns a value of NULL $ - //Use session - //First determine if the session variable exists, and if it does not exist, create the if(!Empty($_session[' admin '])) { - $mysess=$_session[' admin '];Wuyi } the //Delete a session, delete a delay session, delete multiple sessions, end the current session - //1 Deleting a single session Wu unset($_session[' admin ']); - //2 deleting multiple sessions About $_session=Array();//is to empty the data inside the session array. $ //3 ending the current session - //If the entire session ends, you should unregister all session variables and then use the Session_destroy () function to clear the end of the current session and empty all resources - unset($_session[' admin ']); - Session_destroy(); A +
PHP Cookie and session