简体   繁体   English

PHP会话变量不在页面之间保存?

[英]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,您可以尝试:

  1. Changing the code in portal so it just dumps out the session so you can see what you've got: session_start(); 更改门户网站中的代码,以便它只是转储会话,以便您可以看到您所拥有的内容:session_start(); var_dump($_SESSION); 后续代码var_dump($ _ SESSION);
  2. Checking to make sure the error reporting is enabled, as PHP helps you identify many potential issues quite quickly (eg, index doesn't exist, the headers were already sent, etc.): ini_set('display_errors','1'); 检查以确保启用错误报告,因为PHP可以帮助您快速识别许多潜在问题(例如,索引不存在,标题已经发送等):ini_set('display_errors','1'); error_reporting(E_ALL); 使用error_reporting(E_ALL);
  3. You can check your PHP config file (php.ini) to make sure that there are no settings causing session issues directly. 您可以检查PHP配置文件(php.ini)以确保没有直接导致会话问题的设置。

NOTE: For testing purposes only. 注意:仅用于测试目的。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM