In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to solve the problem that php can not deliver session". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to solve the problem that php can't transmit session".
The solution that php cannot pass session is as follows: 1. Open cookie;2 in the client, check browser problems and access cookie;3, and open session.use_trans_sid in php.ini.
This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer
The solution to the problem that SESSION can not be transferred across pages in PHP
Friends who have used SESSION in PHP may encounter the problem that SESSION variables cannot be passed across pages. This bothered me for many days, and finally thought about and solved the problem by looking up the data. In my opinion, the reasons for this problem are as follows:
1. Cookie is disabled on the client
2. There is a problem with the browser and cannot access cookie temporarily.
3. Session.use_trans_sid = 0 in php.ini or the-- enable-trans-sid option is not turned on at compile time
What causes it? Let me explain:
Session is stored on the server side (session is stored as a file by default). According to the session id provided by the client, the user's file is obtained and the value of the variable is obtained. Session id can use the client's Cookie or Http1.1 protocol Query_String (that is, the "?" of the accessed URL. To pass it to the server, and then the server reads the directory of Session. That is, session id is to obtain the ID of the session variable stored on the service. When the code session_start (); runs, a session file is generated on the server, followed by a unique corresponding session id, and the definition session variable is stored in some form in the session file just generated. With session id, you can fetch the defined variables. After the spread, in order to use session, you must execute session_start (); another session file will be generated, corresponding to the corresponding session id, with this session id can not take out the variables in the first session file mentioned earlier, because this session id is not the "key" to open it. If you add the code session_id ($session id) before session_start (); no new session file will be generated, but the session file corresponding to this id will be read directly.
By default, session in PHP uses the client's Cookie to save the session id, so when there is a problem with the client's cookie, it will affect the session. It must be noted that session does not necessarily have to rely on cookie, which is why session is smarter than cookie. When the client's Cookie is disabled or there is a problem, PHP automatically attaches the session id to the URL, so that the session variable can be used across pages through session id. However, this attachment is also subject to certain conditions, that is, "session.use_trans_sid = 1 in php.ini or the-- enable-trans-sid option is turned on at compile time."
Knowing the above, now let's put aside cookie and use session. There are three main ways:
1. Set session.use_trans_sid = 1 in php.ini or open the-- enable-trans-sid option at compile time to let PHP automatically pass session id across pages.
2. Manually pass the value through URL and hide the form to pass session id.
3. Save session_id in the form of file, database, etc., and call it manually in the process of spreading pages.
Use examples to illustrate:
S1.phps2.php
Run the above code, when the client cookie is normal, you should be able to get the result "people's Republic of China".
Now you manually close the client's cookie, and then run it, you may not get the results. If you do not get the result, then "set session.use_trans_sid = 1 in php.ini or open the-- enable-trans-sid option at compile time", and get the result "people's Republic of China".
This is the way 1 mentioned above.
Let's talk about way 2:
The modified code is as follows:
S1.php
S2.php method 3:
Login.html
< html > < head > < title >Login
< meta http - equiv = " Content-Type " content = " text/html; charset=GB2312 " > < body >Please log in:
< form name = " login " method = " post " action = " mylogin1.php " >User name:
< input type = " text " name = " name " > < br >Password:
< input type = " password " name = " pass " > < br > < input type = " submit " value = " 登录 " >Mylogin1.php
Mylogin2.php
Also please turn off the cookie test, user name: laogong password: 123This is saved through the file session id, the file is: e:/tmp/phpsid.txt, please determine the file name or path according to your own system.
As for the method of using database, I won't give an example, which is similar to the method of file.
To sum up, the above methods have one thing in common, that is, get the session id on the previous page, and then find a way to pass it to the next page, in the next page of session_start (); add the code session_id (passed session id) before the code.
At this point, I believe you have a deeper understanding of "how to solve the problem that php can not deliver session". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.