我一般用php程序生成的:1.validate_code.php
作用:产生随机验证码,并生成图片
<?php
header ("Content-type: image/png");
session_start();
$_SESSION[’validate_code’] = strtoupper(substr(md5(rand()),20,6));
$im = @imagecreate (130, 40)
or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($im, 200, 200, 200);//设置干扰像素,防止被OCR
for ($i=0;$i<=128;$i++)
{
$point_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255));
imagesetpixel($im,rand(2,128),rand(2,38),$point_color);
}//逐个画上验证码字符
for ($i=0;$i<=5;$i++)
{
$text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255));
$x = 10 + $i * 20;
$y = rand(5,20);
imagechar ($im, 5, $x, $y, $_SESSION[’validate_code’]{$i}, $text_color);
}//输出PNG图像
imagepng ($im);
imagedestroy ($im);
?> 2.login.php
作用:生成登录界面,显示验证码图片
部分关键代码(不是为了保密,是HTML代码太多,无助于理解程序,所以省省篇幅)
<?php
...
session_start();
...
?>
<td align="right">验证码:</td>
<td>
<input name="validate_code" type="text" id="validate_code" size="8">(0-9,A-F共16个字符,没有字母o只有数字0)
</td>
3.validate_user.php
作用:验证用户登录部分关键源代码:
<?php
session_start();
if (strtoupper($HTTP_POST_VARS[’validate_code’]) != $_SESSION[’validate_code’])
{
echo ’<script language="Javascript">alert("认证失败:验证码错误,单击确定重试。");history.go(-1);</script>’;
unset($_SESSION[’admin_type’]);
unset($_SESSION[’validate_code’]);
exit;
}
else
验证用户名密码是否匹配
?>
作用:产生随机验证码,并生成图片
<?php
header ("Content-type: image/png");
session_start();
$_SESSION[’validate_code’] = strtoupper(substr(md5(rand()),20,6));
$im = @imagecreate (130, 40)
or die ("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate ($im, 200, 200, 200);//设置干扰像素,防止被OCR
for ($i=0;$i<=128;$i++)
{
$point_color = imagecolorallocate ($im, rand(0,255), rand(0,255), rand(0,255));
imagesetpixel($im,rand(2,128),rand(2,38),$point_color);
}//逐个画上验证码字符
for ($i=0;$i<=5;$i++)
{
$text_color = imagecolorallocate ($im, rand(0,255), rand(0,128), rand(0,255));
$x = 10 + $i * 20;
$y = rand(5,20);
imagechar ($im, 5, $x, $y, $_SESSION[’validate_code’]{$i}, $text_color);
}//输出PNG图像
imagepng ($im);
imagedestroy ($im);
?> 2.login.php
作用:生成登录界面,显示验证码图片
部分关键代码(不是为了保密,是HTML代码太多,无助于理解程序,所以省省篇幅)
<?php
...
session_start();
...
?>
<td align="right">验证码:</td>
<td>
<input name="validate_code" type="text" id="validate_code" size="8">(0-9,A-F共16个字符,没有字母o只有数字0)
</td>
3.validate_user.php
作用:验证用户登录部分关键源代码:
<?php
session_start();
if (strtoupper($HTTP_POST_VARS[’validate_code’]) != $_SESSION[’validate_code’])
{
echo ’<script language="Javascript">alert("认证失败:验证码错误,单击确定重试。");history.go(-1);</script>’;
unset($_SESSION[’admin_type’]);
unset($_SESSION[’validate_code’]);
exit;
}
else
验证用户名密码是否匹配
?>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<SCRIPT LANGUAGE="JavaScript">
<!--
function rr()
{
var a = Math.random() + ""; alert(a.substr(2,4));
}
//-->
</SCRIPT>
</HEAD><BODY>
<input type=button onclick="rr()" value="rand">
</BODY>
</HTML>
var number = Math.random();
你的js能生成4位随即数没错,但如果直接显示面不做成验证码图片之类的东西对于验证来说起不到做用吧
//*******************功能介紹*************************************
//功能介紹:銀行帳號生成器//帳號分配規律:帳號由10位純數字組成
//整個帳號分為三部分
//第一部分等於Math.random()*2000+Math.random()*Math.random())%10
//第二部分等於(Math.random()*intd+(Math.random()*5632+intd))%10
//第三部分等於Math.random()*cursor+(Math.sqrt(Math.random()*12596%3))
//cursor=(Math.random()*9356+Math.sin(Math.random()))%10
//最後多於十位的取前十位的數字
//*******************功能介紹*************************************//參數說明:de是出生日期對象的字符串
//返回值:返回已經生成的帳號
function IDcardAccounts(de)
{
var id="";
var end=0;
for(var i=0;i<3;i++)
{
end=(Math.random()*2000+Math.random()*Math.random())%10;
end=parseInt(end);
id+=end.toString();
}
for(var i=0;i<4;i++)
{
var intc=parseInt(de.substr(i,1));
var intd=parseInt(de.substr(i,1));
var end=(Math.random()*intd+(Math.random()*5632+intd))%10;
end=parseInt(end);
if(id.length==10)
{
return id.substr(0,10);
break;
}
id+=end.toString();
}
for(var i=0;i<3;i++)
{
var cursor=(Math.random()*9356+Math.sin(Math.random()))%10;
var end=Math.random()*cursor+(Math.sqrt(Math.random()*12596%3));
end=parseInt(end);
if(id.length==10)
{
return id.substr(0,10);
break;
}
id+=end.toString();
}
return id.substr(0,10);
}