Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of php Jump session loss

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you about how to solve the problem of php jump session loss. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

The solution to the loss of php jump session: 1, open the corresponding file with Notepad; 2, choose the format to UTF-8 without bom format encoding; 3, save the file and re-upload it to the server.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How to solve the problem of php jump session loss?

Php Jump Page session lost session Mechanism

1. The session value can be saved and obtained on the same page, but not across pages.

two。 Before the two pages start session_start (), the session_id ("myid") is set and no value is obtained.

Check that the default saved directory of session does not exist after use.

Reason 2

For a project developed by thinkphp, after logging in successfully and then jumping to the login page, it is normal to output session after submitting information, there is no problem, but after the page jumps, session is lost and cannot be logged in normally.

By looking up the data, it is found that it is the cause of the bom header. Due to the limitation of the COOKIE exit mechanism, COOKIE cannot send out files that already have BOM at the beginning of these files (because PHP has already sent the header before COOKIE is sent), so the login and logout functions are invalid. All functions that rely on COOKIE and SESSION are invalid.

The correct way to deal with it is to remove the bom of some files. In general, there are bom problems in the entry file. My method is to open the file with Notepad++, encode the file in UTF-8 without bom format, save it, and upload it to the server again. But it must be noted that before removing the bom and uploading to the server, you need to delete the source file on the server, and the upload overlay cannot remove the bom.

Session mechanism

Session is a session mechanism on the server side. When the client requests the server to create a session, the server will first detect whether the request contains a unique sessionID. If so, the server has created a session for the user. As long as the user's session is retrieved for use by the user according to the sesionID, if there is no sessionID, the server will create a new session for the user with a unique server sessionID. After the creation is completed, the sessionID will be returned to the client by the server and saved locally to the client.

Generally speaking, the mechanism for saving the session ID is Cookie, but since Cookies can be artificially prohibited, it is necessary to ensure that after Cookies is prohibited, the conversation can still be conducted through session, usually through url rewriting, in the form of http://...../xxx;. Jsessionid= ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBnFD75aPnrF7C2HmdnV6QZBnlerjQ99zWpBnFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBnFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBnFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBnFD75aPnrF7C2HmdnV6QZBnEbzWoWiBYEnLerjQ99zWpBn

In order to maintain state throughout the interaction, this session id must be included after the path that each client may request.

Another is the misunderstanding about session failure:

When talking about the session mechanism, we often hear the misconception that "as long as you close the browser, session disappears." In fact, you can imagine the example of membership card, unless the customer takes the initiative to sell the card to the store, otherwise the store will not easily delete the customer's information. The same is true for session, unless the program notifies the server to delete a session, otherwise the server will always remain, and the program usually sends an instruction to delete the session when the user is doing log off. However, the browser never actively notifies the server that it is going to shut down before shutting down, so the server will never have a chance to know that the browser has been closed, so there is the illusion that most session mechanisms use session cookie to save the session id, but after closing the browser, the session id disappears, and the original session cannot be found when you connect to the server again. If the cookie set by the server is saved to the hard disk, or if you use some means to rewrite the HTTP request header issued by the browser and send the original session id to the server, you can still find the original session by opening the browser again.

It is precisely because closing the browser will not cause the session to be deleted, forcing the server to set an expiration time for the seesion. When the expiration time is longer than the last time the client uses session, the server can think that the client has stopped its activity and delete the session to save storage space.

The above is the editor for you to share how to solve the problem of php jump session loss, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report