简体   繁体   English

某些会话变量在页面之间变为空/空

[英]Some Session variables become empty / null between pages

Something odd is going on. 奇怪的事情正在发生。 I have been testing a web application on my local machine and it works perfectly fine. 我已经在本地计算机上测试了一个Web应用程序,并且运行良好。 Session's are being handled perfectly. 会话的处理非常完美。

Recently, when I promoted the application to production, everything works well except the some of the session variables not being saved between pages. 最近,当我将应用程序推广到生产环境时,除了某些会话变量未保存在页面之间之外,其他所有东西都运行良好。

It seems like all of the newly created session variables that I have added to the application are NOT being saved between pages and all the ones that already existed before the changes were made, ARE being saved between pages. 似乎我添加到应用程序中的所有新创建的会话变量都没有保存在页面之间,而在进行更改之前已经存在的所有会话变量都没有保存在页面之间。

I was thinking maybe it has something to do with the php.ini or some security setting perhaps? 我在想也许与php.ini或某些安全设置有关? What makes this hard for me to troubleshoot is that SOME but not all SESSION's are being lost between pages. 使我很难进行故障排除的原因是,有些(但不是全部)会话在页面之间丢失了。

The 1st page nav contains all SESSION vars as needed, 10 session vars. 第一页导航包含所需的所有SESSION变量,以及10个会话变量。 All of the new vars that were created and saved on the first page become null / empty on the any page other than the first and the number of SESSION vars drops to 9. 在第一页上创建并保存的所有新var都在除第一页之外的任何页面上变为null /空,并且SESSION var的数量降至9。

I greatly appreciate any advice on what is causing this problem and how to troubleshoot this problem! 我非常感谢有关导致此问题以及如何解决此问题的任何建议!

NOTE: the last four variables are newly created, all others have existed before the new changes. 注意:最后四个变量是新创建的,所有其他变量在新更改之前都已存在。

Page Nav 1: 页面导航1:

echo 'ID: ' . session_id() . ' <br/><br/>';
        echo 'SAVE PATH: ' . session_save_path() . ' <br/><br/>';
        var_dump($_SESSION);

Output 输出量

ID: 8rd3paua61caaqd09ahoc0km42

SAVE PATH: D:\php5\session

array(10) { ["termstamp"]=> int(1383577150) ["timestamp"]=> int(1383577150) ["tm"]=> int(1383577150) ["userid"]=> string(6) "153355" ["authenticated"]=> bool(true) ["auth"]=> bool(true) ["joinMeta"]=> string(0) "" ["selectMeta"]=> string(0) "" ["search_queryyy"]=> array(12) { [0]=> string(27) "sec.lastname LIKE '%smith%'" [1]=> string(0) "" [2]=> string(0) "" [3]=> string(0) "" [4]=> string(0) "" [5]=> string(0) "" [6]=> string(0) "" [7]=> string(43) "sec.has_status != 99 && sec.has_status != 6" [8]=> string(0) "" [9]=> string(0) "" [10]=> string(0) "" [11]=> string(0) "" } ["testtttttt"]=> string(17) "SOMETHING INTO IT" }

Page Nav 2 and greater: Page Nav 2及更高版本:

echo 'ID: ' . session_id() . ' <br/><br/>';
        echo 'SAVE PATH: ' . session_save_path() . ' <br/><br/>';
        var_dump($_SESSION); 

Output: 输出:

ID: 8rd3paua61caaqd09ahoc0km42

SAVE PATH: D:\php5\session

array(10) { ["termstamp"]=> int(1383577150) ["timestamp"]=> int(1383577150) ["tm"]=> int(1383577150) ["userid"]=> string(6) "153355" ["authenticated"]=> bool(true) ["auth"]=> bool(true) ["joinMeta"]=> string(0) "" ["selectMeta"]=> string(0) "" ["search_queryyy"]=> NULL ["testtttttt"]=> string(17) "SOMETHING INTO IT" } 

Thanks in advance! 提前致谢!

Have you considered storing these values in input type="hidden" fields as a backup plan? 您是否考虑过将这些值存储在input type="hidden"字段中作为备份计划?

Work on a variation from this, perhaps this will push you in the right direction and see where it goes wrong. 对此进行变种的尝试,也许这会把您推向正确的方向,并找出错误的出在哪里。

<?php
    foreach ($_SESSION as $key=>$value)
    {
?>
       <input type="hidden" name="<?php echo $key; ?>" value="<?php echo $value; ?>" />
<?php
    }
?>

Note: Code untested and will probably not work, but you get the picture... 注意:代码未经测试,可能无法正常工作,但是您得到了图片...

如果会话变量在一个页面上而不在其他页面上运行,则意味着(很可能)您在其他页面上缺少session_start()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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