天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php生成圖形驗(yàn)證碼幾種方法小結(jié)

我們先來檢查一下自己的php是不是打開了gd庫。
復(fù)制代碼 代碼如下:
<?php
if(extension_loaded('gd')) {
  echo '你可以使用gd<br>';
  foreach(gd_info() as $cate=>$value)
    echo "$cate: $value<br>";
}else
  echo '你沒有安裝gd擴(kuò)展';
?>

如果有返回信息就正確可以常用使用了
例1
復(fù)制代碼 代碼如下:
<?php
/**
 * vCode(m,n,x,y) m個(gè)數(shù)字  顯示大小為n   邊寬x   邊高y
 * 自己改寫記錄session $code
 */
session_start();
vCode(4, 15); //4個(gè)數(shù)字,顯示大小為15
function vCode($num = 4, $size = 20, $width = 0, $height = 0) {
 !$width && $width = $num * $size * 4 / 5 + 5;
 !$height && $height = $size + 10;
 // 去掉了 0 1 O l 等
 $str = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVW";
 $code = '';
 for ($i = 0; $i < $num; $i++) {
  $code .= $str[mt_rand(0, strlen($str)-1)];
 }
 // 畫圖像
 $im = imagecreatetruecolor($width, $height);
 // 定義要用到的顏色
 $back_color = imagecolorallocate($im, 235, 236, 237);
 $boer_color = imagecolorallocate($im, 118, 151, 199);
 $text_color = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
 // 畫背景
 imagefilledrectangle($im, 0, 0, $width, $height, $back_color);
 // 畫邊框
 imagerectangle($im, 0, 0, $width-1, $height-1, $boer_color);
 // 畫干擾線
 for($i = 0;$i < 5;$i++) {
  $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
  imagearc($im, mt_rand(- $width, $width), mt_rand(- $height, $height), mt_rand(30, $width * 2), mt_rand(20, $height * 2), mt_rand(0, 360), mt_rand(0, 360), $font_color);
 }
 // 畫干擾點(diǎn)
 for($i = 0;$i < 50;$i++) {
  $font_color = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
  imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $font_color);
 }
 // 畫驗(yàn)證碼
 @imagefttext($im, $size , 0, 5, $size + 3, $text_color, 'c:/WINDOWS/Fonts/simsun.ttc', $code);
 $_SESSION["VerifyCode"]=$code;
 header("Cache-Control: max-age=1, s-maxage=1, no-cache, must-revalidate");
 header("Content-type: image/png;charset=gb2312");
 imagepng($im);
 imagedestroy($im);
}
?>

例2
使用php,結(jié)合session和GD庫擴(kuò)展開發(fā)的一個(gè)生成驗(yàn)證碼的例子(w3c推薦),可以很方便的用于項(xiàng)目中。而且樣式美觀
復(fù)制代碼 代碼如下:
//首先開啟session
session_start();
//定義前臺(tái)顯示驗(yàn)證碼長(zhǎng)&寬
$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = './monofont.ttf';
//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 10;
$random_lines = 30;
$captcha_text_color="0x142864";
$captcha_noice_color = "0x142864";
//定義要生成驗(yàn)證碼的字符串
$code = '';
$i = 0;
while ($i < $characters_on_image) {
$code .= substr($possible_letters, mt_rand(0, strlen($possible_letters)-1), 1);
$i++;
}
$font_size = $image_height * 0.75;
$image = @imagecreate($image_width, $image_height);
/* setting the background, text and noise colours here */
$background_color = imagecolorallocate($image, 255, 255, 255);
$arr_text_color = hexrgb($captcha_text_color);
$text_color = imagecolorallocate($image, $arr_text_color['red'],
        $arr_text_color['green'], $arr_text_color['blue']);
$arr_noice_color = hexrgb($captcha_noice_color);
$image_noise_color = imagecolorallocate($image, $arr_noice_color['red'],
        $arr_noice_color['green'], $arr_noice_color['blue']);
/* generating the dots randomly in background */
for( $i=0; $i<$random_dots; $i++ ) {
imagefilledellipse($image, mt_rand(0,$image_width),
 mt_rand(0,$image_height), 2, 3, $image_noise_color);
}
/* generating lines randomly in background of image */
for( $i=0; $i<$random_lines; $i++ ) {
imageline($image, mt_rand(0,$image_width), mt_rand(0,$image_height),
 mt_rand(0,$image_width), mt_rand(0,$image_height), $image_noise_color);
}
/* create a text box and add 6 letters code in it */
$textbox = imagettfbbox($font_size, 0, $font, $code);
$x = ($image_width - $textbox[4])/2;
$y = ($image_height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $font , $code);
/* Show captcha image in the page html page */
header('Content-Type: image/jpeg');// defining the image type to be shown in browser widow
imagejpeg($image);//showing the image
imagedestroy($image);//destroying the image instance
//設(shè)置session,做驗(yàn)證
$_SESSION['6_letters_code'] = $code;
function hexrgb ($hexstr)
{
  $int = hexdec($hexstr);
  return array("red" => 0xFF & ($int >> 0x10),
               "green" => 0xFF & ($int >> 0x8),
               "blue" => 0xFF & $int);
}

個(gè)人推薦推薦第二個(gè)生成驗(yàn)證碼程序代碼,各位同學(xué)可嘗試參考對(duì)比哦,最后一個(gè)是W3C標(biāo)準(zhǔn)生成的也是利用了php gd庫。

php技術(shù)php生成圖形驗(yàn)證碼幾種方法小結(jié),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 一受多攻高h | 国产69精品久久久久观看软件 | yellow2019在线观看视频 | 依人青青青在线观看 | 亚洲精品久久久久69影院 | 久久99久久成人免费播放 | 99久久久久亚洲AV无码 | 精品爽爽久久久久久蜜臀 | 四川少妇大战4黑人 | 午夜精品久久久久久影视riav | 久久a级片| 青青青青久久久久国产的 | 奶头从情趣内衣下露了出来AV | 99精品视频在线观看re | 快播黄色电影 | 欧美人妖12p | 粗暴玩烂货调教 | 久久亚洲精品中文字幕 | 国产精品高潮呻吟AV久久96 | 2020最新无码国产在线视频 | 一进一出抽搐gif免费60秒 | 欧美精品色婷婷五月综合 | 女人吃男人的鸡鸡 | 欧美雌雄双性人交xxxx | 人人插人人射 | 99精品中文字幕在线观看 | 人人碰国产免费线观看 | 琪琪热热色原日韩在线 | 欧美精品亚洲精品日韩专区一 | 乡土女性网动态图解 | 高h肉肉乳共妻 | 亚洲欧美中文在线一区 | 精品久久久久亚洲 | 男女边吃奶边做边爱视频 | 日本免费一本天堂在线 | J午夜精品久久久久久毛片 jzz大全18 | 在线黑人抽搐潮喷 | 被爽到叫呻呤视频免费视频 | 5278欧美一区二区三区 | 久久午夜夜伦痒痒想咳嗽P 久久午夜夜伦鲁鲁片无码免费 | 日本性hd |