"; then pass it to the server to see the server's parameter configuration, indicating that the user ID is the identified session; finally, change the session's Name is assigned Havi and session is output."/> "; then pass it to the server to see the server's parameter configuration, indicating that the user ID is the identified session; finally, change the session's Name is assigned Havi and session is output.">

Home>Article>Backend Development> Solution to PHP session failure and not delivery

Solution to PHP session failure and not delivery

卡哇伊
卡哇伊 Original
2020-07-06 13:43:02 3269browse

The solution to the problem that PHP session fails and is not passed: First write a php file with the content "a3358401e79a3858445207450bf7e497"; then pass it to the server to see the server's parameter configuration, indicating that the user ID is The identified session; finally assign the name of the session to Havi and output the session.

Solution to PHP session failure and not delivery

In PHP, the session cannot be passed to the next page. There are generally two situations:

Let’s first write a php file:a3358401e79a3858445207450bf7e497, and pass it to the server to see the server’s parameter configuration.

Go to thesessionsection and see that thesession.use_trans_sidparameter is set to 0.

This parameter specifies whether to enable transparent SID support, that is, whethersessionis passed along with the URL. My personal understanding is that once this parameter is set to 0, then each URL will start asession. In this way, subsequent pages cannot track the session of the previous page, which is what we call undeliverable. The two pages generate twosessionfiles on the server side and are not related.

So one way is to change the value ofsession.use_trans_sidto 1 in the configuration filephp.ini.

Of course we know that not everyone has the authority to change the configuration of php, so what are the indirect solutions?

Let’s use two examples to illustrate:

File 1 test1.php

”.$_SESSION['name'].””; ?>

File 2: test2.php

Every page must be written to open the session, otherwise it will still not work properly

So, the key point Addsession_id(SID); beforesession_start();, so that when the page is converted, the server uses the user saved in the serversessionfolder Thesessionsolves the problem of delivery.

However, some colleagues will report that if thesessionof multiple users is written in one SID, then the value of the Session will be Can't perform anymore. So there is another way to solve this problem. No need to addsession_id(SID);The premise is that you have configuration permissions on the server's php.ini:

If output_buffering# is changed to ON, the truth will not be clear.

The second possible reason is that there is no read permission to the folder where the server savessession, so go back tophpinfo.php,View the saved address ofsession:

session.save_path: var/tmp

所以就是检查下var/tmp文件夹是否可写。

写一个文件:test3.php来测试一下:

如果返回bool(false),证明文件夹写权限被限制了,那就换个文件夹咯,在你编写的网页里加入:

//设置当前目录下session子文件夹为session保存路径。$sessSavePath = dirname(__FILE__).’/session/’; //如果新路径可读可写(可通过FTP上变更文件夹属性为777实现),则让该路径生效。if(is_writeable($sessSavePath) && is_readable($sessSavePath)){session_save_path($sessSavePath);}

The above is the detailed content of Solution to PHP session failure and not delivery. 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