PHP没有将一些会话变量传递给另一个脚本

时间:2015-01-21 15:37:45

标签: php session

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

所有这些脚本1都是$ _GET餐厅和列表名称,并显示一个表单,用户可以填写代码字段并提交。

更糟糕的是,我创建了另一个脚本(此调用脚本的简化版本),它只设置会话变量并调用相同的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>

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:-1)

查看是否所有文件都保存为没有BOM的UTF-8,而不仅仅是UTF-8。 此BOM会使会话无效。

查看是否所有文件都被调用,因为它们位于同一个子域中。

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

......使用不同的子域名不应该有效。