php 图片验证码用javascript证验

WBOY
Release: 2016-06-13 11:31:54
Original
761 people have browsed it

php 图片验证码用javascript验证

本帖最后由 cyyjm 于 2013-08-15 11:48:37 编辑 现在我的图片验证是交到后台验证,感觉影响查询速度。如何交给javascript验证?
php生成页面代码如下:
<br /><?php <br />session_start(); <br />//生成验证码图片 <br />Header("Content-type: image/PNG"); <br />$im = imagecreate(44,18); // 画一张指定宽高的图片 <br />$back = ImageColorAllocate($im, 245,245,245); // 定义背景颜色 <br />imagefill($im,0,0,$back); //把背景颜色填充到刚刚画出来的图片中 <br />$vcodes = ""; <br />srand((double)microtime()*1000000); <br />//生成4位数字 <br />for($i=0;$i<4;$i++){ <br />$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255)); // 生成随机颜色 <br />$authnum=rand(1,9); <br />$vcodes.=$authnum; <br />imagestring($im, 5, 2+$i*10, 1, $authnum, $font); <br />} <br />$_SESSION['VCODE'] = $vcodes; <br />for($i=0;$i<100;$i++) //加入干扰象素 <br />{ <br />$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255)); <br />imagesetpixel($im, rand()%70 , rand()%30 , $randcolor); // 画像素点函数 <br />} <br />ImagePNG($im); <br />ImageDestroy($im); <br />?><br />
Copy after login


前台样式:
<br />		 <form name="form1" method="post" action="719.php" ><br />			   <p><label>电脑编号:</label><input name="username" type="text" size="20"></p><br />			   <p class="prmt"><label>用户密码:</label><input name="pass" type="password" size="20">  <input type="submit" name="Submit" value="查 询"></p><br />			   <p class="prmt"><label>验 证 码:</label><input name="ask" type="text" size="6"><img  id="refresh" src="muth.php" onclick="document.getElementById('refresh').src='muth.php'"/ alt="php 图片验证码用javascript证验" ></p><br />		</form> <br />
Copy after login

这样,后台里就能通过开启session_start();并与$_SESSION['VCODE']判断验证码是否正确。
我如何能够通过javascript做验证,而不需要php后台来验证。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!