next00.php
<?php session_start();?>
<script>
function chk(){
if(document.getElementById("num").value==<?php echo $_SESSION["code"];?>)
{
alert("ok");
return true;
}
else{
alert(document.getElementById("num").value+"-"+<?php echo $_SESSION["code"];?>);
return false;
}
}
</script><form action="next00.php" method="post" onsubmit="return chk()">
<input type="text" size="10" name="num" id="num"/><img src="image.php">
<input type="submit" value="submit">
</form><?php
if($_POST["num"]!=""){
if($_POST["num"]==$_SESSION["code"]){
echo "ok";
}
else{
echo "no";
echo $_POST["num"]." ".$_SESSION["code"];
}
}
?>
image.php<?php
session_start();
header("Content-type:text/html;charset=UTF-8");
header("Content-type:image/gif");
$image=imagecreatetruecolor(80,30);
$bg=imagecolorallocate($image,255,255,255);
$color=imagecolorallocate($image,255,0,255);
$num=rand(10000,40000);
imagestring($image,5,10,10,$num,$color);
$_SESSION["code"]=$num;
imagegif($image);
?>
首次验证是好用的,执行一次回来之后就有问题了。js得到的数据好像总滞后一次
<?php session_start();?>
<script>
function chk(){
if(document.getElementById("num").value==<?php echo $_SESSION["code"];?>)
{
alert("ok");
return true;
}
else{
alert(document.getElementById("num").value+"-"+<?php echo $_SESSION["code"];?>);
return false;
}
}
</script><form action="next00.php" method="post" onsubmit="return chk()">
<input type="text" size="10" name="num" id="num"/><img src="image.php">
<input type="submit" value="submit">
</form><?php
if($_POST["num"]!=""){
if($_POST["num"]==$_SESSION["code"]){
echo "ok";
}
else{
echo "no";
echo $_POST["num"]." ".$_SESSION["code"];
}
}
?>
image.php<?php
session_start();
header("Content-type:text/html;charset=UTF-8");
header("Content-type:image/gif");
$image=imagecreatetruecolor(80,30);
$bg=imagecolorallocate($image,255,255,255);
$color=imagecolorallocate($image,255,0,255);
$num=rand(10000,40000);
imagestring($image,5,10,10,$num,$color);
$_SESSION["code"]=$num;
imagegif($image);
?>
首次验证是好用的,执行一次回来之后就有问题了。js得到的数据好像总滞后一次
在<img src="image.php">上面的代码,$_SESSOIN['code']还没有被赋值,
直到执行到<img src="image.php">,$_SESSION['code']才开始被赋值应该使用Ajax进行判断
如果flag不为真 form不能提交,
当code修改后 进行ajax判断,如果成功修改 flag的值,
//unset($_SESSION['code']);?><form action="test.php" method="post">
<input type="text" size="10" name="num" id="num"/><img src="image.php">
<input type="submit" value="submit">
</form><?php
if(isset($_POST["num"])){
if($_POST["num"]==$_SESSION["code"]){
echo "ok";
}
else{
echo "no";
echo $_POST["num"]." ".$_SESSION["code"];
}
}
?>
js那一段可以完全不要。