PHP 不会将某些会话变量传递给另一个脚本


PHP not passing SOME session variables to another script

我疯狂地试图理解为什么下面的脚本(我们称之为script1)将会话变量$_SESSION['emptystcode']传递给bulkstOLD.php而不是其他两个:$_SESSION['dlstrest']和$_SESSION['dllist']。我有session_start();在被调用脚本的第一个命令行上。

此 script1 所做的只是_GET餐厅和列表名称 $,并显示一个表单,用户可以在其中填写 CODE 字段并提交它。

更糟糕的是,我创建了另一个脚本(此调用者脚本的简化版本),该脚本仅设置会话变量并调用相同的bulkstOLD.php并且工作正常。 我想知道这是否与_GET美元有关。任何帮助将不胜感激。谢谢!!

这是代码:

<?php
session_start();
include ('logged.php'); 
require_once ('functions.php');
$acisversion = $_SESSION['acisversion']; 
reset_all();
$cyear = date(Y);
$cmonth = date(M);
$cday = date(d);
$configs = include('config.php');
$_SESSION["module"] = 'st';
$_SESSION['favstlists_ref'] = 0;
$strest = $dlstrest = $_GET['dlstrest'];
$favstlist = $dllist = $_GET['dllist'];
$restname = 'restname_'.$strest;
$stlistrest = $configs[$restname]; 
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>ACIS - Edit Lists</title>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script> 
<script type="text/javascript" src="stmenu.js"></script>
<style type="text/css">
@import url(acis.css);
</style>
<script type="text/javascript" src="js.js"></script>
</head>
<body>
    <div id="content">
<?php
  $_SESSION['stcodesub'] = $stcodesub = $stcode = ($_POST["stcodein"]);
  dbfile_init() ; 
   $_SESSION['stcode'] = $stcode;
if(isset($_POST["editSave"]))
      { 
            connect_db ();
            if (!empty($stcode))
            {                  
               check_code_for_st_list();
                $emptystcode = 0;
            }
            else
            { 
                $emptystcode = 1;                
            }
            $_SESSION['dlstrest'] = $dlstrest;
            $_SESSION['dllist'] = $dllist;
            $_SESSION['emptystcode'] =  $emptystcode;  
            if ((!$emptystcode and $codestok) or $emptystcode)
                { 
                    echo '<META HTTP-EQUIV="Refresh" Content="0; URL=bulkstOLD.php">';
                    exit;  
                }
     }
?>
<table width="100%" border="0" align="center">
  <tr>
     <td width="223" align="left"></td>
     <td width="111" align="right"></td>
  </tr>
</table>

</style>
<form method="post" id="editLists" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>"> 
<table width="739" border="0" align="center" cellspacing="0" bgcolor="#171717">
     <tr>
    <td colspan="3" 
    style="color:#00CC00;
    text-align: left;
    padding: 0;
    background: #2e2e2e url(images/nav_bar.jpg) repeat-x;
    font-size: 0.9em;
    color: white;
    height:16px;"><script type="text/javascript" src="mainmenu.js"></script></td>
    </tr>
  <tr>
    <td width="502"><h2 style="color:red;"> Atualizar Listas Favoritas de Pratos</h2></style></td>
    <td width="231" colspan="2" align="right"><?php echo $configs[footer];?></td>
    </tr>
  <tr>
    <td colspan="3" align="right"  ><table width="100%" border="0" align="center">
      <tr>
        <td align="center">Restaurante:</td>
        <td width="84" align="center" valign="bottom">Adicionar Código</td>
        <td width="350" align="center">Lista a ser atualizada:</td>
        <td width="150" align="left" valign="bottom"><span class="error"><?php echo $favErr;?></span></td>
        </tr>
      <tr>
        <td width="135" align="center"><b><?php echo $stlistrest; ?></b></td>
        <td align="center">
<?php
         echo $stcodeline;
?>
        </td>
        <td align="center"><b><?php echo $dllist; ?></b></td>
        <td align="right"><input type="submit" name="editSave" style="background-color: #009900; color: #FFFFFF;" value="Submeter" /></td>
        </tr>
      </table></td>
  </tr>
</table>
</form>

<?php

$_SESSION["module"] = 'st';
?>
</div>

</body>
</html>

对你的问题的唯一可能的解释是,你可能没有在一开始就写<?php session_start();?>,在任何HTML标签(甚至是doctype)之前。把它写在每个相关的 php 文档之上。

查看是否所有文件都保存为没有 BOM 的 UTF-8,而不仅仅是 UTF-8。此物料清单禁用会话。

并查看是否所有文件都在同一子域中调用。

www.domain.com/file1.php,
ww2.domain.com/file2.php,
domain.com/file3.php

。使用不同的子域应该不起作用。