<?php
session_start();
function games_code(){
$str = "012356789abcdefghijklmnopqrstuvwxyz"; // 输出字符集
$n=4; // 输出串长度
$len = strlen($str)-1;
for($i=0 ; $i<$n; $i++){
$s .= $str[rand(0,$len)];
}
return $s;
}
?>
<?php
if($_POST["passcode"]!=""){
//echo $_POST["passcode"];
if($_POST["passcode"]!=$_SESSION["code"]){
echo "验证码错误";
}else{
echo "填写正确";
}
}
?>
<form name="form1" action="?" method="post">
<input type="text" name="passcode" id="passcode" />
<?
$code=games_code();
echo $code;
$_SESSION["code"]=$code;
//echo $_SESSION["code"];
?>
<input type="submit" value="提交" />
</form>