<?php
$digit = $_GET['digit'];
if (!$digit) exit;$im = imagecreate(62,20);
$black = ImageColorAllocate($im, 0,0,0);
$white =ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im,200,200,200);
imagefill($im,0,0,$gray);
//½«ËÄλÕûÊýÑéÖ¤Âë»æÈëͼƬ
imagestring($im, 5, 10, 3, $digit, $black);
for($i=0;$i<200;$i++) //¼ÓÈë¸ÉÈÅÏóËØ
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>另:此程序需要GD库的支持
$digit = $_GET['digit'];
if (!$digit) exit;$im = imagecreate(62,20);
$black = ImageColorAllocate($im, 0,0,0);
$white =ImageColorAllocate($im, 255,255,255);
$gray = ImageColorAllocate($im,200,200,200);
imagefill($im,0,0,$gray);
//½«ËÄλÕûÊýÑéÖ¤Âë»æÈëͼƬ
imagestring($im, 5, 10, 3, $digit, $black);
for($i=0;$i<200;$i++) //¼ÓÈë¸ÉÈÅÏóËØ
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()%70 , rand()%30 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
?>另:此程序需要GD库的支持
解决方案 »
- php连接服务器上的mysql数据库问题
- PHP DOM XML 错误 'DOMException' with message 'Not Found Error'
- php session 丢失
- php调用c#的webService遇到的问题..
- 调试php的Xdebug配置不对,网上找了一些方法,可就是无法正常工作!
- mysql数据库备份问题
- 请教个问题
- [转] 大家进来看看, 用 C 写的 CGI 留言板程序 (CSP 源程序分析)
- 表单使用enctype="multipart/form-data"属性后,不能取得post数据。如:
- ?在邮件系统中LDAP是干什么用的? postfix是什么 ?那位能解释一下?
- sohu新闻右面的广告是怎么放上去的,他们怎么可以在生成静态文件的基础上包含想要的文件啊?
- 遇到一个奇怪的问题,一直好好的,今天就突然发威了
欢迊来到麦高网-私活兼职首选平台 www.mgao.net
如果能够直接获得验证码的字符串内容的话,验证码还有什么存在的意义呢?一般实现方法都是将验证码内容存放在session中
//////////////////////////////////////////////////////////////////////////////
<?php/***********************************************************************
pwd.php
***********************************************************************/
class png_pwd{ var $image_x;
var $image_y; var $pwd_word = 5;
var $pwd_len;
var $password ='';
var $ctctct = 1; function png_pwd()
{
$this ->image_x = "45";
$this ->image_y = "25"; $this ->pwd_word = "4";//密码字号(可选为1-5)
$this ->pwd_len = "4";//密码长度
//$this ->pwd_word = imageloadfont ( "./font/georgia.ttf"); }
function my_rand($min,$max)
{
mt_srand((double)microtime()*1000000*getmypid()*$this->ctctct);
$this->ctctct +=523;
return mt_rand($min,$max);
}
//生成随机字符串函数
function Randstr()
{
$chars='0123456789';
// characters to build the password from
// seed the random number generater (must be done)
//mt_srand((double)microtime()*1000000*getmypid());
return substr($chars,($this->my_rand(0,strlen($chars)-1)),1);
} //创建图片
function createImage()
{
$pwd = '';
for($i =0;$i<$this->pwd_len;$i++) $pwd .= $this->Randstr();
$image = imagecreatetruecolor ($this->image_x , $this->image_y);
//定义背景色
$background_color = imagecolorallocate($image , 0xFF , 0xFF , 0xFF);
//定义文字及边框颜色
$black_color = imagecolorallocate($image , 0x00 , 0x00 , 0x00);
//定义雪花点颜色
//$gray_color = imagecolorallocate($image , 0x80 , 0x80 , 0x80); //生成矩形边框
imagefilledrectangle ($image , 0 , 0 , $this->image_x-1 , $this->image_y - 1 , $background_color);
imagerectangle($image , 0 , 3 , $this->image_x - 1 , $this->image_y - 1 , $black_color); //循环生成雪花点
for ($i = 0 ; $i < 400 ; $i++)
{
$gray_color = imagecolorallocate($image , 128+$this->my_rand(0,128) , 128+$this->my_rand(0,128) , 128+$this->my_rand(0,128));
imagesetpixel($image , mt_rand(1 , $this->image_x-2) , mt_rand(4 , $this->image_y-2) , $gray_color);
//echo $gray_color."<br>";
}
//把随机字符串输入图片
for ($i = 0 ; $i < strlen($pwd) ; $i++){
$font_color = imagecolorallocate($image , $this->my_rand(0,100) , $this->my_rand(0,100) , $this->my_rand(0,100));
//$rn_char = $this->Randstr();
imagestring($image , $this->pwd_word , 4+$i*10 , 6 , $pwd{$i} , $font_color);
//$this->password .=$rn_char;
//echo $rn_char."<br>";
}
//exit;
//return $image;
session_start();
$_SESSION["vCode"] = $pwd;
header("Content-type:image/png");
Imagepng($image);
}
}if(isset($_GET["show"]) && $_GET["show"] == "true")
{
//use and show it
$im = new png_pwd; $im->createImage();
//$im->show();
}
?>//////////////////////////////////////////////////////////////////////////////在登陆表单中现实这个图片:
<img src="pwd.php?show=true">//////////////////////////////////////////////////////////////////////////////在登陆验证代码中加入如下的代码:
if($_POST['vCode']!=$_SESSION['vCode']) {
//处理验证码不正确
}
关于这个 呵呵 忘了说
在登陆框中别忘了加一个文本框:
<input type="text" name="vCode" >