Cookie / Session mechanism

Cookie mechanism

  Cookie is the browser (User Agent) access to some websites that a set of data stored in the client for the websites to track users, implementing user-defined function.

  Cookie's Domain and Path attribute identifies the Cookie is a website which is sent to the browser; Cookie Expires attribute identifies the effective time of Cookie, Cookie after the effective time of the past, the data is automatically deleted.

  If you do not set an expiration time, then this Cookie life cycle during a browsing session, simply close the browser window, Cookie disappeared. This lifetime is browsing session is called a session of the Cookie Cookie. Session Cookie is generally not stored on the hard disk, but kept in memory. If you set the expiration time, the browser will save the Cookie to your hard drive, open the browser again closed, Cookie these remain valid until the expiration time exceeds the set. Cookie is stored on the hard disk can be shared between different browser process, such as two IE windows. For the Cookie is stored in memory, different browsers have different approach.

 

Session mechanism

  Session is located on the server side is similar to the structure HashTable (implemented for each Web development techniques may not be the same, hereinafter referred directly HashTable) to store user data, when the browser sends a request for the first time, the server automatically generates a HashTable and a Session ID to uniquely identify the HashTable, and sends it to the browser in response. When the second transmission request browser, a server will respond before the Session ID in the request sent together to the server, the server extracts the Session ID from the request, and all the Session ID and saved compared to find this user corresponding HashTable.

  Under normal circumstances, the server within a certain time (default 20 minutes) to save the HashTable, over the time limit, it will destroy the HashTable. Before destruction, the programmer can be some of the user data in the form of Key and Value of this temporarily stored in the HashTable. Of course, there will be saved using the database after the HashTable serialized, this benefit is not the time constraints, the downside is the increase over time, this database will be rapid expansion, especially when traffic increases. General or to take the former approach to relieve pressure on the server.

Guess you like

Origin www.cnblogs.com/bluealine/p/11058400.html