我正在使用会话值在带有 ajax 的页面之间增加 2 个变量..简单的一个..我在 Page1 中使用了 session_start 并在第 1 页中将会话变量初始化为 0..在 page2 中我根据条件初始化它们..我似乎增加一次,它们没有效果..这是我的操作页面..
<?php
session_start();
?>
<html>
<body>
<?php
$j=isset($_POST['commit']) && $_POST['commit'];
if($j)
{
$num=rand(0, 100);
?>
<div>
<div id="inner_1">
<?php
if($num<27){
echo "Result:Hit";
$_SESSION['off']=$_SESSION['off']=+1;
echo "Offensive Player:";
if(isset($_SESSION['off'])){echo $_SESSION['off'];}else{echo '0';}
echo "Defensive Player:";
if(isset($_SESSION['on'])){echo $_SESSION['on'];}else{echo '0';}
}
else
{
echo "Result:Miss";
$_SESSION['on']=$_SESSION['on']=+1;
echo "Offensive Player:";
if(isset($_SESSION['off'])){echo $_SESSION['off'];}else{echo '0';}
echo "Defensive Player:";
if(isset($_SESSION['on'])){echo $_SESSION['on'];}else{echo '0';}
} ?>
</div>
</div>
<?php } ?>
</body>
</html>
第1页
<?php
session_start();
$_SESSION['off']=0;
$_SESSION['on']=0;
?>