[英]PHP Session variables not saving between pages?
Login page: 登录页面:
<?php
session_start();
#echo session_id ();
$_SESSION["auth"]= "yes";
echo '<a href="Portaltest.php?t='.time().'">portal page link. Auth set to: {$_SESSION["auth"]}</a>';
?>
Portal page: 门户页面:
<?php session_start();
echo "auth = {$_SESSION["auth"] } <BR />";
echo session_id ();
?>
The auth
session is lost between the two pages somehow! 以某种方式在两页之间丢失了auth
会话!
Edit 编辑
Here is a test url: 这是一个测试网址:
http://proserv01.services.lyris.com/NFPInsurance/UnsegmentedMemberReport/logintest.php http://proserv01.services.lyris.com/NFPInsurance/UnsegmentedMemberReport/logintest.php
When trouble-shooting sessions, there are a few things I tend to do, but let's start with your code. 在进行故障排除时,我倾向于做一些事情,但让我们从你的代码开始。
Here is an updated version of your page code so you actually see the value stored in $_SESSION['auth'] (your quotes were causing some trouble): 这是您的页面代码的更新版本,因此您实际上看到存储在$ _SESSION ['auth']中的值(您的引号导致了一些问题):
<?php
session_start();
$_SESSION["auth"] = "yes";
echo '<a href="Portaltest.php?t='.time().'">portal page link. Auth set to: ' . $_SESSION["auth"] . '</a>';
?>
Here is the updated version of the portal page, which removes the additional space after the closing curly bracket: 以下是门户网站页面的更新版本,它在关闭大括号后删除了额外的空格:
<?php
session_start();
echo "auth = {$_SESSION["auth"]} <BR />";
?>
Now, if you don't see the auth with these revisions, you can try: 现在,如果您没有看到带有这些修订的auth,您可以尝试:
I am unsure as to what the expected results are, yet I will submit this as an answer with explanations set inside PHP comments. 我不确定预期结果是什么,但我会将其作为答案提交给PHP注释中的解释。
Give this a try: 尝试一下:
<?php
session_start();
$_SESSION["auth"]= "yes";
// will echo: portal page link. Auth set to: yes
echo '<a href="Portaltest.php?t='.time().'">portal page link. Auth set to: ' . $_SESSION["auth"] . '</a>';
echo "<br>";
// will echo: auth = yes
echo "auth = {$_SESSION["auth"] } <BR />";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.