Home  >  Article  >  Backend Development  >  Use URL to transmit SESSION information

Use URL to transmit SESSION information

WBOY
WBOYOriginal
2016-07-25 08:44:38961browse

In learning PHP, sessions are what we often use, so today we will talk about sessions in details in detail;

1. 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: transferring session based on URL

If the session is transmitted according to the basic session method, the cookie in the user's browser will be used. Once the user closes the cookie, the session will not work! 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, and 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 cookies, the output is empty
SID When the user closes 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 to use the id in the parameters 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! !

The above is the entire content of this article, I hope you all like it.

URL, SESSION


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn