php数字母验证码

<?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>

    A+
发布日期:2009年08月04日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: