我试图诊断出一种PHP问题。 我将数值转至<代码>_SESSION 阵列,这些数值不为阵列。 I used var_dump($_SESSION)
to see what was being re and I have array (0){}
. 即使我知道会议正在举行,而且各种价值观也在增加,情况也是如此。
我的法典(指数.php)的简化版本如下:
<?php
session_start();
var_dump($_SESSION);
if ($_REQUEST[ query ] == "" or is_null($_REQUEST[ query ])) {
$errormsg = "You must enter a search term to query. Please try again.";
}
?>
<form name="product_search" id="product_search" method="post" action="index.php">
<input size="60" type="text" name="query" id="query" <?php echo "value="" . $_REQUEST[ query ] . "" "; ?>/>
<?php if (isset($errormsg)) {echo "<span class="errormsg">" . $errormsg . "</span>";} ?>
<input type="submit" class="searchBtn" value="Search"/>
<?php
$_SESSION[ query ] = foo ;
$_SESSION[ search_field ] = man ;
$_SESSION[ results ] = chu ;
?>
var_dump($_SESSION); //Will dump array(3) {...}
重犯错误:
- Load the page. No problem here;
var_dump($_SESSION)
at the top returnsarray(0) {}
, which is expected, and the one at the botton returns a three-member array, also as expected. - Submit the form with something in the query field (to defeat the validation). Despite the
$_SESSION
variables being set on the previous page load, the first dump still returnsarray(0) {}
.
我在此简化了我的代码,以处理这一问题,但我还有一页,正在毫无困难地收回“SESSION”变量(第一个var_dump
产生一个成员阵列)。 这里的问题是,我向自己提交表格,如果是的话,除了<代码>_SESSION阵列外,是否还有其他办法将价值从一页的负荷传递到下一页? 我审视了购买力平价文件,并搜索了高和低,但却没有发现任何帮助。
I should also note that the session ID is the same across page loads, so it appears session state is being maintained from page load to page load.
事先得到帮助。