doushi4864 2011-01-25 21:05 采纳率: 100%
浏览 46
已采纳

PHP会话变量没有保存(虽然有些是)

I have been unable to figure out this problem - it just doesn't make any sense.

The server is PHP 5.2.6 running on Windows NT PDP-IIS 5.2 build 3790.

First I have confirmed sessions ARE working via this test script:

<?php 
session_start(); 
if (!isset($_SESSION['counter'])) $_SESSION['counter']=0;
echo "Counter ".$_SESSION['counter']++.".<br><a href=".$_SERVER['PHP_SELF'].">reload</a>"; 
?>

The counter increments - it works.

My site is using a custom built MVC framework (I wrote it), and I put the last code of the app function to this for testing purposes:

echo session_id(); echo '<pre>'; var_dump($_SESSION); echo '</pre>';
session_write_close(); exit();

The first few lines of this file are:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
session_start();

The session dumps and looks as expected. Now I go to the server and open up the session file - and the result appears to depend on what browser I'm using. For Chrome and Safari, the session file was empty. For Opera and IE8 the session file looked fine. I'll get to FireFox in a minute - but at this point FireFox appeared fine.

So for testing purposes immediately following session_start() I added the following lines:

$_SESSION['bogus'] = -5;
$_SESSION['test'] = 'other';

I closed my browsers and tried the site again so I could be sure I had a new session. Again Opera and IE8 session files appeared fine. Both Chrome and Safari had the 'bogus' and 'test' values, but my other SESSION value was missing. FireFox at first had the same problem as Chrome and Safari at this point - but upon refreshing the page, the rest of the session showed up. Refreshing did not help Chrome or Safari.

Here is what the var_dump looks like at this point:

array(3) {
  ["bogus"]=>
  int(-5)
  ["test"]=>
  string(5) "other"
  ["saved_form"]=>
  array(1) {
    ["dgvSJM"]=>
    array(4) {
      ["method"]=>
      string(4) "post"
      ["processor"]=>
      string(0) ""
      ["formid"]=>
      string(10) "searchForm"
      ["fields"]=>
      array(2) {
        ["searchTerm"]=>
        array(5) {
          ["label"]=>
          string(10) "SearchTerm"
          ["type"]=>
          string(6) "search"
          ["required"]=>
          bool(false)
          ["multiple"]=>
          bool(false)
          ["selectempty"]=>
          string(6) "B5BMXw"
        }
        ["formInput_0"]=>
        array(5) {
          ["label"]=>
          string(0) ""
          ["type"]=>
          string(6) "submit"
          ["required"]=>
          bool(false)
          ["multiple"]=>
          bool(false)
          ["selectempty"]=>
          string(6) "TkZUfo"
        }
      }
    }
  }
}

I created a different website with a different subdomain, and copied my code exactly over - and it works fine 'saved_form' shows up perfectly in the session files. So I tried deleting the original website and recreating it - didn't help the problem.

Anyone know what is going on and/or how I can fix it?

Thanks.

  • 写回答

1条回答 默认 最新

  • douli4852 2011-02-08 14:57
    关注

    I believe I have solved this issue.

    After my application processes the 'saved_form' key - which it does on every run - it removes it for security reasons.

    I am using a rewrite module for nicer links (module is IIRF).

    This is where the problem was - though it is no fault of the module, just my rules.

    After the page was rendered and the session saved - the browser made another request to favicon.ico, however the rules I setup caused that request to get run through my app and the form processed and removed from the session - thus causing the odd behavior I was seeing. I added a rule to ignore it, and it is working again.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端