本文介绍了如何跨页面使用存储和使用会话变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
访问一页后,我想开始一个会话并存储一个会话变量:
When one page is accessed, I would like to start a session and store a session variable:
<?php
session_start();
$_SESSION['myvar']='myvalue';
?>
然后从另一页上,我要检查该会话变量是否已存储:
Then from another page, I would like to check if that session variable has been stored:
<?php
session_start();
echo("1");
if(isset($_SESSION['myvar']))
{
echo("2");
if($_SESSION['myvar'] == 'myvalue')
{
echo("3");
exit;
}
}
?>
此代码对我不起作用.
推荐答案
根据对该问题的评论,似乎缺乏调整后的 session.save_path 导致了PHP会话处理程序的这种行为.只需指定一个存在的目录(在文档根目录之外),该目录就可以被PHP读取和写入,以解决此问题.
Reasoning from the comments to this question, it appears a lack of an adjusted session.save_path causes this misbehavior of PHP’s session handler. Just specify a directory (outside your document root directory) that exists and is both readable and writeable by PHP to fix this.
这篇关于如何跨页面使用存储和使用会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!