Home >Backend Development >PHP Problem >What to do if php session cannot be used

What to do if php session cannot be used

藏色散人
藏色散人Original
2021-03-11 09:37:332645browse

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.

What to do if php session cannot be used

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!

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