欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP高自定義性安全驗證碼代碼

 更新時間:2011年11月27日 00:22:28   作者:  
根據(jù)網(wǎng)上的一個驗證碼修改。 自定義性非常強,需要的朋友可以參考下。
復制代碼 代碼如下:

<?php
public function captcha(){
$font_dir = $_SERVER ["DOCUMENT_ROOT"] . "your_ttf_file.ttf"; // 字體庫
$img_w = 58; // 設置圖片寬
$img_h = 20; // 設置圖片高
$font_size = 11; // 字體大小
$angle_l = -10; // 左偏角
$angle_r = 10; // 右偏角
$code_str = "ABCDEFGHJKLMNPQRSTUVWXYZ36";
$word_len = 4; // 驗證碼位數(shù)
$padding = 5; // 每兩個文字之間間隔
$margin = 2; // 左側邊距
$base_line = 15; // 文字基線位置
$base_line_offset = 2; // 基準線偏移量
$pixel_num = 3; // 雜點數(shù)目基數(shù)
$pixel_color= 8; // 雜點只有 $pixel_color 種顏色 總的雜點數(shù)為$pixel_num*$pixel_color
$noise_font_size = 1; // 雜點字體大小
$session_key= "my.xoyo_captcha"; //自定義session鍵名

header("Cache-Control: no-cache, must-revalidate");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Pragma: no-cache");
header("Cache-control: private");
header('Content-Type: image/png');

session_start();
$word = "";
$code_str_len = strlen($code_str) - 1;
for ($i = 0; $i < $word_len; $i++) {
$word.= $code_str[rand(0, $code_str_len)];
}
$_SESSION [$session_key] = strtolower($word);
$image = imagecreatetruecolor($img_w, $img_h);
imagefilledrectangle($image, 0, 0, $img_w - 1, $img_h - 1, imagecolorallocate($image, mt_rand(235, 255), mt_rand(235, 255), mt_rand(235, 255)));

//繪制雜點
for($i = 0; $i < $pixel_color; $i++){
$noise_color = imagecolorallocate( $image, mt_rand(150,225), mt_rand(150,225), mt_rand(150,225) );
for($j = 0; $j < $pixel_num; $j++) {
imagestring( $image, $noise_font_size, mt_rand(-10, $img_w), mt_rand(-10, $img_h), $code_str[mt_rand(0, $code_str_len)], $noise_color );
}
}

//繪制文字
for ($i = 0; $i < $word_len; ++$i) {
$color = imagecolorallocate($image, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));
imagettftext($image, $font_size, mt_rand($angle_l, $angle_r), $margin, mt_rand($base_line-$base_line_offset, $base_line+$base_line_offset), $color, $font, mb_substr($word, $i, 1, 'utf-8'));
$margin += (imagefontwidth($font_size) + $padding);
}

imagepng($image);
imagedestroy($image);
exit;
}

相關文章

  • PHP網(wǎng)頁游戲學習之Xnova(ogame)源碼解讀(六)

    PHP網(wǎng)頁游戲學習之Xnova(ogame)源碼解讀(六)

    這篇文章主要介紹了PHP網(wǎng)頁游戲Xnova(ogame)源碼解讀的公共代碼,需要的朋友可以參考下
    2014-06-06
  • php根據(jù)日期判斷星座的函數(shù)分享

    php根據(jù)日期判斷星座的函數(shù)分享

    下面提供一個用PHP來判斷指定一日期屬于哪個星座的函數(shù),需要的朋友可以參考下
    2014-02-02
  • php中的strpos使用示例

    php中的strpos使用示例

    strpos()函數(shù)返回字符串在另一個字符串中第一次出現(xiàn)的位置。如果沒有找到該字符串,則返回 false,下面看示例使用方法
    2014-02-02
  • 如何使用jQuery+PHP+MySQL來實現(xiàn)一個在線測試項目

    如何使用jQuery+PHP+MySQL來實現(xiàn)一個在線測試項目

    本文將結合實例給大家介紹如何使用jQuery+PHP+MySQL來實現(xiàn)在線測試題,包括動態(tài)讀取題目,答題完畢后臺評分,并返回答題結果。
    2015-04-04
  • YII2框架使用控制臺命令的方法分析

    YII2框架使用控制臺命令的方法分析

    這篇文章主要介紹了YII2框架使用控制臺命令的方法,結合實例形式分析了YII2使用控制臺命令的相關步驟、原理與操作技巧,需要的朋友可以參考下
    2020-03-03
  • 使用phpstorm和xdebug實現(xiàn)遠程調試的方法

    使用phpstorm和xdebug實現(xiàn)遠程調試的方法

    vs的斷點調試功能很強大有木有,能查看所有變量有木有。php調試很麻煩有木有,echo,var_dump寫得你想吐了有木有。想體驗一下ide調試的快感嗎?那就來使用xdebug吧
    2015-12-12
  • php讀取mysql的簡單實例

    php讀取mysql的簡單實例

    讀取數(shù)據(jù)庫我們需要利用php中的函數(shù)連接數(shù)據(jù)庫然后再利用sql查詢 表中的數(shù)據(jù)再遍歷出來即可了,下面我們來看一個簡單讀取mysql實例
    2014-01-01
  • PHP實現(xiàn)遠程下載文件到本地

    PHP實現(xiàn)遠程下載文件到本地

    經(jīng)常寫采集器發(fā)布接口需要使用到遠程附件的功能,所以自己寫了一個PHP遠程下載文件到本地的函數(shù),一般情況下已經(jīng)夠用了,如果服務器支持CURL函數(shù),程序則會優(yōu)先選擇CURL,有需要的小伙伴可以參考下。
    2015-05-05
  • php 中文字符串首字母的獲取函數(shù)分享

    php 中文字符串首字母的獲取函數(shù)分享

    這篇文章介紹了php 中文字符串首字母的獲取函數(shù),有需要的朋友可以參考一下
    2013-11-11
  • php arsort 數(shù)組降序排序詳細介紹

    php arsort 數(shù)組降序排序詳細介紹

    php arsort函數(shù)用于將數(shù)組中的元素按照降序進行排序,如果排序成功則返回true,否則返回false,本文章向大家講解arsort函數(shù)的基本語法及使用實例,需要的朋友可以參考下
    2016-11-11

最新評論