当前位置:网站首页>Session working principle and typical application analysis

Session working principle and typical application analysis

2020-12-07 10:53:17 osc_ 15fvklrg

1、 establish Session

When a user accesses a server , If the server is enabled Session, The server will create a SESSION, Creating this SESSION When , The server first checks whether the request sent by the user contains a SESSION ID, If it includes a SESSION ID This indicates that the user has logged in and created for this user before SESSION, Then the server follows this SESSION ID Put this SESSION Find it in the memory of the server , If the client request does not contain SESSION ID, Create a for the client SESSION And generate one with this SESSION dependent SESSION ID. This SESSION ID Is the only one. 、 Not repeated 、 It's not easy to find regular strings , This SESSION ID Will be returned to the client in this response to save , And this one is preserved SESSION ID It's just COOKIE, In this way, the browser can automatically send the identity to the server according to the rules during the interaction .

2、 Use Session

We know that IE in , We can use the tools in Internet In the options, put Cookie prohibit , Then will not appear the client's Cookie It's forbidden , that SESSIONID It can't be used anymore ? I found some information to explain , There can be other mechanisms in COOKIE Still be able to put Session id Back to the server .

A technique that is often used is called URL rewrite , Is to put Session id Attach directly to URL The latter kind of path is as URL Additional information about the path , In the form of :

https://www.qilucms.com /xxx;jSession=ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764;

The other is attached as a query string to URL Back , In the form of :

https://www.why114.com /xxxjSession=ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764

There is also a form of hidden fields . The server will automatically modify the form , Add a hidden field , So that when the form is submitted Session id Back to the server .

Session Working principle and typical application analysis

Session effect

Session The basic function is to store some information of user and server conversation in the server . Typical applications are :

1、 Determine whether the user is logged in .

2、 Shopping cart function .

Session Example question

Existing systems A,B; hypothesis A The system can run independently web System , That is, it can be handled directly with the browser session, B The system is based on mobile Of , Need to call A Function interface of the system ,

In maintaining A Without changing , That is, login verification ,session With the same storage ,B The system can handle the requests from the front end users .

The solution here is to use PHP Realization

After the user login successfully , Will be preserved session Of session-id Return to B System , then B Every time the system requests other interfaces, it will bring session_id.

A The system is in session_start with session_id(session_id);

such B The system can safely call A

版权声明
本文为[osc_ 15fvklrg]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/20201207105113698d.html