如何用PHP编写一个识别长尾词的图片验证码系统?
- 内容介绍
- 文章标签
- 相关推荐
本文共计278个文字,预计阅读时间需要2分钟。
php// 第一段代码生成随机图片code2.php dog, pic1=> cat, pic2=> fish, pic3=> bird);:index=> rand(0, 3);$value=$table['pic' . $index];$_SESSION['image']=$value;?>
//第一段代码生成随机图片------code2.php
<?php //开启session以用于保存生成的内容 session_start(); $table=array( "pic0"=>"dog", "pic1"=>"cat", "pic2"=>"fish", "pic3"=>"bird" ); $index=rand(0,3); $value=$table['pic'.$index]; $_SESSION['authcode']=$value; //得到随机生成的图片名 $filename=dirname(__FILE__).'/pic'.$index.'.jpg'; $content=file_get_contents($filename); header('Content-type:image/jpg'); echo$content; ?>
//第二段代码实线表单的验证
<?php if(isset($_REQUEST['authcode'])){ session_start(); if($_REQUEST['authcode']==$_SESSION['authcode']){ echo"right"; }else{ echo"sadstory<br/>"; echo$_REQUEST['authcode']; } } ?> <!DOCTYPEhtml> <html> <head> <title></title> </head> <body> <formaction="./code1.php"method="post"> <p>picture:<imgid="cap_img"border="1"src="./code2.php?r=<?phpechorand();?>"width="100"height="30"/></p> <br/> //通过js切换另外一张图片 <ahref="javascript:void(0)"onclick="document.getElementById('cap_img').src='./code2.php?r='+Math.random()">changepicture</a> <p>words:<inputtype="text"name="authcode"value=""/></p> <p><inputtype="submit"value="sub"></p> </form> </body> </html> ?>
/*代码的路径是linux的路径*/
本文共计278个文字,预计阅读时间需要2分钟。
php// 第一段代码生成随机图片code2.php dog, pic1=> cat, pic2=> fish, pic3=> bird);:index=> rand(0, 3);$value=$table['pic' . $index];$_SESSION['image']=$value;?>
//第一段代码生成随机图片------code2.php
<?php //开启session以用于保存生成的内容 session_start(); $table=array( "pic0"=>"dog", "pic1"=>"cat", "pic2"=>"fish", "pic3"=>"bird" ); $index=rand(0,3); $value=$table['pic'.$index]; $_SESSION['authcode']=$value; //得到随机生成的图片名 $filename=dirname(__FILE__).'/pic'.$index.'.jpg'; $content=file_get_contents($filename); header('Content-type:image/jpg'); echo$content; ?>
//第二段代码实线表单的验证
<?php if(isset($_REQUEST['authcode'])){ session_start(); if($_REQUEST['authcode']==$_SESSION['authcode']){ echo"right"; }else{ echo"sadstory<br/>"; echo$_REQUEST['authcode']; } } ?> <!DOCTYPEhtml> <html> <head> <title></title> </head> <body> <formaction="./code1.php"method="post"> <p>picture:<imgid="cap_img"border="1"src="./code2.php?r=<?phpechorand();?>"width="100"height="30"/></p> <br/> //通过js切换另外一张图片 <ahref="javascript:void(0)"onclick="document.getElementById('cap_img').src='./code2.php?r='+Math.random()">changepicture</a> <p>words:<inputtype="text"name="authcode"value=""/></p> <p><inputtype="submit"value="sub"></p> </form> </body> </html> ?>
/*代码的路径是linux的路径*/

