澳门新葡萄京官网首页php验证码类

//session_start();class icode{function __construct(){
header(‘Content-Type:image/png’);}function __destruct(){
imagedestroy($png);}function getcode($len,$type){ switch ($type){ case
1; $str = 1234567890; break; case 2; $str = abcdefghijklmnopqrstuvwxyz;
break; case 0; $str = 1234567890abcdefghijklmnopqrstuvwxyz; break; }
$result = ; $length = strlen($str) – 1; $num = 0; for
($i=0;$i$len;$i++){ $num = rand(0,$length); $a = $str[$num]; $result =
$result.$a; } /*Before using it,you should use session_start()*/
$_SESSION[‘icode’] = $result;//Store in session. //echo
session:.$_SESSION[‘icode’]; //die(); $png = imagecreate(60,30);
$white = imagecolorallocate($png,255,255,255);//background $red =
imagecolorallocate($png,255,0,0); $blue =
imagecolorallocate($png,0,0,255); $brown =
imagecolorallocate($png,100,0,0); $black =
imagecolorallocate($png,0,0,0);//Identifying Code
imagefill($png,0,0,$white); $k = rand(0,3); if (0 == $k){ for
($n=0;$n60;$n++){ $y = 15*sin($n/30*pi());
imagesetpixel($png,$n,15+$y,$red); } }else if (1 == $k){ for
($n=0;$n60;$n++){ $y = 15*cos($n/60*pi());
imagesetpixel($png,$n,15+$y,$red); } }else if (2 == $k){ for
($n=0;$n60;$n++){ $y = 15*sin($n/45*pi());
imagesetpixel($png,$n,15+$y,$brown); } }else if (3 == $k){ for
($n=0;$n60;$n++){ $y = 15*cos($n/30*pi());
imagesetpixel($png,$n,15+$y,$brown); } } for ($k=0;$k10;$k++){ $i =
rand(3,60);//width $j = rand(3,15);//height
imageline($png,$i-3,$j-3,$i,$j,$black); }
imagestring($png,5,3,5,$result,$blue); $icode = imagepng($png); return
$icode;}}/*测量试验代码$icode = new icode(卡塔尔;$icp = $icode-getcode(6,0卡塔尔国;echo
$icp;*/

作品权归作者全体。商业转发请联系我获得授权,非商业转发请注脚出处。互连网+时代,时刻要保全学习,执手千锋PHP,Dream It Possible。

参照链接:
php点击验证码实时刷新的兑今世码
php验证码刷新与局地刷新的完结形式

?php/*@date 20080514@author hluan

$str .= strtoupper($str);

干脆自个儿搞三个啊。

php验证码程序 验证码 代码 php php 图片验证码

public static function yzm($width=100,$height=40,$length=4,$type=0)

  1. <?php  
  2. class RandCheckCode  
  3. {  
  4.         /*函数名称:get_code() 
  5.         *效果与利益:获得自由字符串 
  6.         * 参数: 
  7.         1、(int)$length = 32 #随便字符长度 
  8.         2、(int)$mode = 0    #随意字符类型, 
  9.         0为大小写保加南宁语和数字,1为数字,2为小写字母,3为大写字母, 
  10.         4为大小写字母,5为大写字母和数字,6为小写字母和数字 
  11.         *回到:得到的字符串 
  12.         */  
  13.         function get_code($length=32,$mode=0State of Qatar//获取随机验证码函数  
  14.         {  
  15.                 switch ($mode)  
  16.                 {  
  17.                         case ‘1’:  
  18.                                 $str=’123456789′;  
  19.                                 break;  
  20.                         case ‘2’:  
  21.                                 $str=’abcdefghijklmnopqrstuvwxyz’;  
  22.                                 break;  
  23.                         case ‘3’:  
  24.                                 $str=’ABCDEFGHIJKLMNOPQRSTUVWXYZ’;  
  25.                                 break;  
  26.                         case ‘4’:  
  27.                                 $str=’ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz’;  
  28.                                 break;  
  29.                         case ‘5’:  
  30.                                 $str=’ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890′;  
  31.                                 break;  
  32.                         case ‘6’:  
  33.                                 $str=’abcdefghijklmnopqrstuvwxyz1234567890′;  
  34.                                 break;  
  35.                         default:  
  36.                                 $str=’ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890′;  
  37.                                 break;  
  38.                 }  
  39.                 $checkstr=”;  
  40.                 $len=strlen($str)-1;  
  41.                 for ($i=0;$i<$length;$i++)  
  42.                 {  
  43.                         //$num=rand(0,$lenState of Qatar;//发生三个0到$len之间的自由数  
  44.                         $num=mt_rand(0,$len卡塔尔国;//发生二个0到$len之间的人身自由数  
  45.                         $checkstr.=$str[$num];  
  46.                          
  47.                          
  48.                 }  
  49.                 return $checkstr;  
  50.         }  
  51.            
  52. /**     函数名称:create_check_image() 
  53.         函数效率:爆发一个校验码的图形 
  54.         参    数:$checkcode:校验码字符串 
  55.         返 回 值:再次来到该图形 
  56. */  
  57.         function create_check_image($checkcodeState of Qatar//发生叁个  
  58.         {  
  59.                 $im=imagecreate(65,22卡塔尔国;//产生三个图片  
  60.                 $black=imagecolorallocate($im,0,0,0State of Qatar;//背景颜色  
  61.                 $white=imagecolorallocate($im,255,255,255State of Qatar;//前途颜色  
  62.                 $gray=imagecolorallocate($im,200,200,200);  
  63.                 imagefill($im,30,30,$gray卡塔尔(قطر‎;//在$im图像的坐标30,30(图像左上角为0,0卡塔尔(قطر‎处用$gray 颜色试行区域填充(即与30,30点颜色相近且周边的点都会被填充卡塔尔国  
  64.                  
  65.                 imagestring($im,5,8,3,$checkcode,$white卡塔尔(قطر‎;//用$white颜色将字符串$checkcode画到$im 所代表的图像的8,3坐标处(那是字符串左上角坐标,整幅图像的左上角为0,0卡塔尔,5是字体大小, 字体只好是1,2,3,4或5,使用内置字体  
  66.                 for ($i=0;$i<120;$i++)  
  67.                 {  
  68.                         $randcolor=imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));  
  69.                         imagesetpixel($im,rand(State of Qatar%70,rand(卡塔尔国%30,$randcolor卡塔尔(قطر‎;//在$im图象上用$randcolor颜色在(rand(卡塔尔国%70,rand(State of Qatar%30State of Qatar坐标(图像左上角为0,0卡塔尔上画一个点  
  70.                 }  
  71.                 header(“Content-type:image/png”);  
  72.                 imagepng($im卡塔尔(قطر‎;//以PNG格式将图像输出到浏览器或文件  
  73.                 imagedestroy($imState of Qatar;//销毁图像$im  
  74.         }  
  75. }  
  76. /* 
  77. $randcode=new RandCheckCode(); 
  78. $checkstring=$randcode->get_code(5,7); 
  79. $image=$randcode->create_check_image($checkstring); 
  80. echo $image; 
  81. */  
  82.   
  83. ?>  

{

英特网有众多的php随机数与验证码的代码与小说,真正适用的从未有过多少个。

$start = (int)$isLight * 128;

千帆竞发本节的php教程 啊,以下代码的贯彻,首要产生能够很好界别叁个get_code(),另一个create_check_image(卡塔尔,输出图像直接调用前面包车型大巴,session(卡塔尔取验证码时直接get_code(State of Qatar就ok,顺带提下使用session时必需定会将session_star(卡塔尔放在最前头。

}

代码如下:

//图片财富

[php] view
plaincopy

protected function setDisturb()

case 1://小写字母

}

$green = mt_rand($start,$end);

}

}

//验证码

public function getLastCode()

}

return false;

protected function randMixed()

public function output()

$offsetX = $i * $perWidth + $delta;

for ($i=0; $i < $this->length; $i++) {

case 3://中文

return $this->code;

$offsetY = ($this->height + $fontSize) / 2;

$ch1 = mt_rand(176,214);

}

{

return $this->code;

{

imagepng($this->image);

$str = ”;

protected function randString()

break;

protected function sendImage()

$v->output();

$str .= chr(mt_rand(ord(‘0’), ord(‘9’)));

}

{

break;

imagesetpixel($this->image, $x, $y, $color);

//将验证码画到画布上

if ($length >= 3 || $length <= 10) {

{

protected function randChinese()

return join(”, $arr);

$str .= chr(mt_rand(ord(‘A’), ord(‘Z’)));

protected function setVerifyCode()

$str = ‘1234567890’;

}

}

class Verify

$str .= chr($ch1) . chr($ch2);

//创立画布并安装浅色背景

}

case 2://大写字母

$ch = rand(0,9);

$delta = ($perWidth – $fontSize) / 2;

$this->type = $type;

$str = $this->randUnknow();

public function __construct($width=200,$height=50,$length=4,$type=0)

protected $width;

return substr(str_shuffle($str), 0, $this->length);

case 0://纯数字

$this->length = $length;

{

}

}

$type = mt_rand(0, 2);

$color = $this->getColor();

$str = $this->randNumber();

protected function randUnknow()

return $str;

for ($i=0; $i < $this->length; $i++) {

break;

break;

protected function createImage()

return $str;

case 2://数字字母混合

protected $type;

$str = $this->randMixed();

$this->setDisturb();

}

break;

{

}

{

$str = $this->randAlpha();

protected $length = 4;

return substr(str_shuffle($str), 0, $this->length);

$lightColor = $this->getColor(true);

}

}

{

header(‘Content-Type:image/png’);

case 0://数字

$ch = mb_substr($this->code, $i, 1);

//提取多少个字符

//长度

$end = $start + 127;

$y = mt_rand(0, $this->height-1);

$red = mt_rand($start,$end);

$str = $this->randChinese();

protected $image;

//类型

$arr = array_fill(0, $this->length, $ch);

if ($propertyName == ‘code’) {

for ($i=0; $i < $total; $i++) {

//画到画布上

{

return $v->getLastCode();

$this->height = $height;

protected $height;

{

default://未知

$arr = range(‘a’, ‘z’);

}

$angle = mt_rand(-30,30);

}

return imagecolorallocate($this->image, $red, $green, $blue);

$this->image = imagecreatetruecolor($this->width,
$this->height);

public function __get($propertyName)

imagedestroy($this->image);

{

return iconv(‘gbk’, ‘utf-8’, $str);

$blue = mt_rand($start,$end);

}

break;

}

$perWidth = $this->width / $this->length;

$x = mt_rand(0, $this->width-1);

switch ($type) {

$str = ”;

$total = $this->width * $this->height / 50;

//高度

protected function randAlpha()

}

{

$str .= chr(mt_rand(ord(‘a’), ord(‘z’)));

$fontSize = $this->height / 2;

protected function getColor($isLight=false)

$v = new Verify($width,$height,$length,$type);

}

$this->width = $width;

imagefill($this->image, 0, 0, $lightColor);

for ($i=0; $i < $this->length; $i++) {

break;

$str = join(”, $arr);

}

protected $code;

{

imagettftext($this->image, $fontSize, $angle, $offsetX, $offsetY,
$color, ‘../../../../public/fonts/lxkmht.ttf’, $ch);

$color = $this->getColor();

{

case 1://纯字母

switch ($this->type) {

//产生验证码字符串

$this->sendImage();

protected function randNumber()

$this->code = $this->randString();

{

$ch2 = mt_rand(161,254);

}

break;

{

$this->createImage();

//宽度

$this->setVerifyCode();

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注