Home >Backend Development >PHP Problem >What to do if php session cannot get the value
# Recommended: "php session cannot get the value because the session is not passed in. The solution is to open the session through the "session_start()" method before using the php session.
PHP Video Tutorial》
I recently encountered this problem when writing PHP. The session will always exist if the entire website is not closed. However, after the session is initialized on one page, I will download it on another page. When the session value was not found, I used echo to print the session information and found that the session was not passed in at all. I thought it was the PHP session that was used in other ways. . . (っ°Д °;)っ, I have only used session in Asp and Jsp before, and finally found the cause of the error. PHP session must be opened before use:session_start ()This statement should be placed in front of all statements that use session, so it is best to write it at the beginning of the php file so as not to forget it. This is the same as using session in other languages. There are some differences. In addition, there are several very useful functions regarding the use of PHP sessions, such as:
isset($_SESSION['view']) // 判断某个session值是否初始化 unset($_SESSION['view']) //删除某个session值 session_destroy(); //谨慎使用 销毁所有的session数据Remember, although many contents in different languages have similarities, you still need to Study the details carefully and don’t always take it for granted~
The above is the detailed content of What to do if php session cannot get the value. For more information, please follow other related articles on the PHP Chinese website!