日期:2014-05-16 浏览次数:20430 次
<?php
srand((double)microtime()*1000000);
$im=imagecreate(50,20); // 新建一个基于调色板的图像
$gray=imagecolorallocate($im,200,200,200);//imagecolorallocate -- 为一幅图像分配颜色
imagefill($im,0,0,$gray); //imagefill -- 区域填充
for($i=0;$i<4;$i++){
$str=mt_rand(1,3);
$size=mt_rand(3,6);
$authnum=substr($_GET['num'],$i,1);
imagestring($im,$size,(2+$i*10),$str,$authnum,imagecolorallocate($im,rand(0,130),rand(0,130),rand(0,130)));
} //imagestring -- 水平地画一行字符串
imagepng($im);
imagedestroy($im);
?>
<html>
<head>
<title>js---判断验证码码是否正确</title>
<script >
function yzm(form){
var num1=Math.round(Math.random()*10000000);
var num=num1.toString().substr(0,4);
form.check2.value=num;
document.write("<img name=codeimg width=50 heigh=20 src='yzm.php?num="+num+"'>");
}
function code(form){
var num1=Math.round(Math.random()*10000000);
var num=num1.toString().substr(0,4);
form.check2.value=num;
document.codeimg.src="yzm.php?num="+num;//这里面的num就是验证码的值
}
function checkYzm(form){
if(form.check.value == ""){
document.getElementById('result').innerHTML = "验证码不能为空";
}else if(form.check.value != form.check2.value){
document.getElementById('result').innerHTML = "验证码错误,请重新输入";
}else{
document.getElementById('result').innerHTML = "验证码输入正确";
}
}
function postForm(form) {
if(form.check.value == "" || form.check.value != form.check2.value)
{
document.getElementById('check').value = '';
document.getElementById('check').focus();
}
else
{
form.submit();
}
}