In the study of php, sessions are what we often use, so today we will Let’s talk about session in conversation in detail;
1. The working mechanism of session:
When the session is opened, the server will save the session file in the server, and then save the session ID number in the browser to obtain the corresponding session information. ;
2. The following is the focus of the article: Transmitting session based on URL
If the session is transmitted according to the basic session method, then the cookie in the user's browser will be used. Once the user closes the cookie, then Session doesn’t work anymore! So next we will put the session ID number on the link address of the website, so that we are not afraid of the user turning off the cookie!
(We take simple user login as an example, When the user turns on cookies, it is transmitted by cookie, when the user turns off cookies, it is transmitted by url)
1. Create a user login page and add
after the action address of the form.
SID When the user turns on the cookie, the output is empty
SID When the user turns off the cookie, the current user session information is output. The specific format is session_name=session_id;
2. Create a page to determine whether the user is logged in;
When session_id() contains parameters, it means that the id in the parameter is used as a reference to find the sessoin file. Note that session_id() must be in front of session_start()
3. Create a logout page
First clear the current user’s session data, and then delete the user’s session file
This whole small case of session transmission based on URL is done! !
This article is original to Wang Yelou’s personal blog. If you want to reprint, please indicate the source: Wang Yelou’s personal blog http://www.ly89.cn/detail/28.html