Home>Article>Backend Development> Solution to PHP session failure and not delivery
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.
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 thesession
section and see that thesession.use_trans_sid
parameter is set to 0.
This parameter specifies whether to enable transparent SID support, that is, whethersession
is 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 twosession
files on the server side and are not related.
So one way is to change the value ofsession.use_trans_sid
to 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); before
session_start();, so that when the page is converted, the server uses the user saved in the server
sessionfolder The
sessionsolves 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 add
session_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 to
phpinfo.php,
View the saved address ofsession:
session.save_path: var/tmp
所以就是检查下var/tmp文件夹是否可写。
写一个文件:test3.php来测试一下:
echo var_dump(is_writeable(ini_get(“session.save_path”))); ?>
如果返回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!