1. The cookie data is stored on the client's browser and the session data is placed on the server.
2, the cookie is not very safe, others can be stored in the local cookie and cookie spoofing, considering that security should use the session.
3. Session will be saved on the server for a certain period of time. When the number of accesses increases, the performance of your server will be compared, and cookies should be used in consideration of mitigating server performance.
4, the limit of a single cookie on the client is 3K, that is, a site in the client store cookies can not be 3 K.
Example, a COOKIE
For example: Setcookie (' user ', ' Zhangsan ', Time () +3600), which represents the user variable value of Zhang San cookie survival time is 1 hours, note that this function belongs to the head function, it is equivalent to the header () Jump function in PHP, You cannot have any output (including spaces) before it.
2. Use $_cookie[' user ' to obtain the COOKIE value. Www.111cn.net
3. Logout Cookie:setcookie (' user ', ' ', Time ()-3600); or Setcookie (' user ');
4.
Delete the client's SessionID in the cookie
if (Isset ($_cookie[session_name ())) {
Setcookie (Session_name (), ", Time ()-30, '/');
}
Example, session
1.//Open Session
Session_Start ();
2.//Clear Session Value
$_session = Array ();
Completely destroy session
Session_destroy ();
Session and Cookie who is more secure
Personally, I think the session is a little safer, and I have a few points of view.
1, if the session and the cookie is as safe, the two will not and to exist at the same time, as long as the cookie is good, let the client to the burden of the server, and for the user is transparent. Why not.
2,session's SessionID is placed in a cookie, to break the session, the first to break the cookie. After breaking the cookie, you want to get Sessionid,sessionid is to have someone login, or start Session_Start to have, you don't know when someone will log in. Second, the SessionID is encrypted, the second time Session_Start, the previous sessionid is no use, the session expires SessionID will also expire, want to in a short time the internal strength of a dense sessionid difficult. Session is for the purpose of a communication, the end of sessions will disappear, and the real cookie exists on the client hard disk of a text file, who security is obvious.
3, if the session is so easily broken, so unsafe, I think most of the existing sites are not safe.
http://www.bkjia.com/PHPjc/727583.html www.bkjia.com true http://www.bkjia.com/PHPjc/727583.html techarticle 1. The cookie data is stored on the client's browser and the session data is placed on the server. 2, the cookie is not very safe, others can analyze the cookie stored in the local and cookie deception, consider ...