Home > Article > Backend Development > What to do if php session cannot be used
php session cannot be used because it is not opened before using the session. The solution is to add the code "session_start()" in front of all statements that use the session.
The operating environment of this article: Windows 7 system, PHP version 7.1, DELL G3 computer
The session of PHP 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 somewhat different from the use of session in other languages. , In addition, regarding the use of PHP sessions, there are several very useful functions, 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. , don’t always take it for granted~
[Recommended learning: "PHP Video Tutorial"]
The above is the detailed content of What to do if php session cannot be used. For more information, please follow other related articles on the PHP Chinese website!