PHP验证码的实现
来源:互联网 发布:帝国cms仿今日头条 编辑:程序博客网 时间:2024/05/10 20:25
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"><img src="validate_code.php
" widht="130" height="40">(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"><img src="validate_code.php
" widht="130" height="40">(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验证码的实现
- php验证码的实现
- PHP验证码的实现
- PHP的验证码实现
- 【php】php验证码的简单实现
- PHP实现验证码的实现
- 图片格式的PHP验证码的实现
- php实现验证码
- PHP实现验证码
- PHP实现验证码
- PHP实现验证码
- php实现验证码
- php实现验证码
- PHP实现验证码
- PHP---验证码实现
- php验证码实现
- 【PHP】验证码实现
- php实现验证码
- 用java生成jpg图片
- resin2.1.14+mysql4.1.12调试jsp时的问题
- Java bytecode assembler : jasmin
- 收藏
- 【收藏】使用网络地址转换 增强网络安全
- PHP验证码的实现
- Excercise 9_1
- 看程序员是怎么喝酒的(搞笑)
- 【收藏】一个老程序员的工作经历 误导中国IT该当何罪
- VC++技术点滴
- 使用FileSystemWatcher监测大文件时,如何判断文件已经创建完成?
- 局域網中共用.net的應用程式.
- 校园求爱信
- 系统维护技术点滴