您好,我对每页开头的以下代码有疑问:
session_start();
if (!isset($_SESSION['a'])){
...create the session from some variables...
$_SESSION['a'] = $var;
$var = $_SESSION['a'];
}else{
$var = $_SESSION['a'];
$what = "some text";
if (isset($_POST['one']) ){
$var = "new input";
$_SESSION['a'] = $var;
echo "one was posted";
}
if (isset($_POST['two']) ){
$var = "new input";
$_SESSION['a'] = $var;
echo "two was posted";
}
}
要发布的表格放在页脚中:
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="one" name="one"/><div>set one</div>
</form>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="two" name="two"/><div>set two</div>
</form>
上面代码背后的逻辑似乎有问题。调用页面并发送帖子问题时,它不会回显并且不会将会话更改为新值。
所以如果有人可以帮助我,我真的很感激。
多谢。
更新:
好的,代码完全可以工作到“其他”部分:
else{
$var = $_SESSION['a'];
if (isset($_POST["one"]) ){
echo "post one was send";
}
if (isset($_POST["two"]) ){
echo "post en was send";
}
echo "session already exists.";
}
这部分只显示回声:会话已存在。整个后置短语不起作用。根据某些变量,页脚将被嵌入。因此 html 中的全部内容将被回显:
echo '...
<ul class="drop_down">
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="one" name="one value="one"/><div>set one</div>
</form>
<form action="'.$_SERVER['PHP_SELF'].'" method="post">
<input type="submit" id="two" name="two" value="two"><div>set two</div>
</form>
</ul>
...';