由網友Tongshuai測試之後發現有BUG,似乎是SESSION部分出了一些問題,很抱歉我沒有測試各CI版本,或許是CI版本的問題,但是Tongshuai也順便提供了他的解決方法,可以直接參考他的回覆內容

The library bug had be find by Tongshuai.It's seem because SESSION problem in different CI version.If you got the same trouble,you can try the solution that Tongshuai's comment
(2009-04-24)

這是什麼?請看http://www.phpcaptcha.org/captcha-gallery/就知道了。

沒錯,他就是驗證圖片產生器這個類別庫源自於 http://www.phpcaptcha.org/整個類別庫只有一個檔案而且相當好使用,所以我就試著把他改成可以放在CI來使用

安裝:

  • 下載Securimage類別庫:http://doublekai.org/files/Securimage_For_CI.zip
  • 複製檔案 libraries / Securimage.php 到 application / libraries
  • 複製檔案 config / Securimage.php 到 application / config
  • 複製目錄 views / fonts 到 application / views

如果你想要馬上測試的話

  • 複製檔案 controlls / welcome.php 到 application / controlls
  • 複製檔案 controlls / image.php 到 application / controlls
  • 複製檔案 views / test.html 到 application / views

What's it? see http://www.phpcaptcha.org/captcha-gallery/

The original source from http://www.phpcaptcha.org/.It seems light and simple to use,so I try to fixed it up for CI framework

Install:

  • Download the Securimage Library from http://doublekai.org/files/Securimage_For_CI.zip
  • Copy file libraries / Securimage.php to application / libraries
  • Copy file config / Securimage.php to application / config
  • Copy dir views / fonts to application / views

if you want to quickstart test

  • Copy file controlls / welcome.php to application / controlls
  • Copy file controlls / image.php to application / controlls
  • Copy file views / test.html to application / views

Example(範例):

Controlls

/**********************
 * controllers / welcome.php 
 **********************/
class Welcome extends Controller {
    function Welcome(){
        parent::Controller();
        $this->load->library('securimage');
        $this->load->helper('url');
        $this->load->helper('html');
    }
    function index(){
        $this->load->view('test.html');
    }
    function check(){
        $inputCode = $this->input->post('imagecode');
        if($this->securimage->check($inputCode) == true){
            $data['result'] = '

=v= PASS!

'; $this->load->view('test.html',$data); } else { $data['result'] = '

/_\ FAILURE

'; $this->load->view('test.html',$data); } } }
/**********************
 * controllers / image.php 
 **********************/
class Image extends Controller {
    function Image(){
        parent::Controller();
        $this->load->library('securimage');        
    }
    function securimage(){
        $this->securimage->show();
    }
}

Views




另外如果對英文苦手的話,我也將設定檔調整位置後中文化了,你可使用下列的設定檔來取代原本的英文設定檔

/***************
 * 目錄路徑設定
 ***************/  
//TTF字型的目錄位置
$securimage['ttf_file'] = APPPATH."views/fonts/elephant.ttf"; 
  
//自訂文字碼清單
$securimage['wordlist_file'] = APPPATH."words/words.txt";  
  
//使用的GD字型
$securimage['gd_font_file'] = APPPATH."views/fonts/gdfonts/bubblebath.gdf";  
  
//語言檔的路徑 
$securimage['audio_path'] = APPPATH."audio";
  
/***************
 * 圖片設定
 ***************/
//圖片的寬度
$securimage['image_width'] = 175;
  
//圖片的高度
$securimage['image_height'] = 45;
  
//圖片的類型
//可選用:SI_IMAGE_PNG, SI_IMAGE_JPG, SI_IMAGE_GIF
$securimage['image_type'] = SI_IMAGE_PNG;

/***************
 * 文字設定
 ***************/
//文字碼的長度
$securimage['code_length'] = 4;
  
//可選用的文字碼字元(小寫會自動被轉為大寫)
$securimage['charset'] = 'ABCDEFGHKLMNPRSTUVWYZ23456789';

//啟動自訂文字碼清單模式(取代亂數文字碼的方法)
$securimage['use_wordlist'] = false;

//啟用GD字型來替代TTF字型
$securimage['use_gd_font'] = false;

//GD字型的大小
$securimage['gd_font_size'] = 20;

//字型大小
$securimage['font_size'] = 24;

//傾斜的最小角度
$securimage['text_angle_minimum'] = -20;

//傾斜的最大角度
$securimage['text_angle_maximum'] = 20;

//文字碼產生的X軸位置
$securimage['text_x_start'] = 8;

//字距的最小程度
$securimage['text_minimum_distance'] = 30;

//字距的最大程度
$securimage['text_maximum_distance'] = 30;

//背景的顏色
$securimage['image_bg_color']="#e3daed";

//文字碼的顏色
$securimage['text_color']="#000000";

//啟用混合的文字顏色
$securimage['use_multi_text'] = true;

//交差使用的文字顏色
$securimage['multi_text_color']="#0a68dd,#f65c47,#8d32fd";

//使用清晰的文字
$securimage['use_transparent_text'] = true;

//清晰的程度
$securimage['text_transparency_percentage'] = 15;

/***************
 * 格線設定
 ***************/
//產生網格線
$securimage['draw_lines'] = true;

//網格線顏色
$securimage['line_color']="#FFFFFF";

//背景網格大小
$securimage['line_distance'] = 10;

//背景網格線的粗線
$securimage['line_thickness'] = 1;

//在背景網格上增加交差線
$securimage['draw_angled_lines'] = true;

//背景網格線是否蓋過文字
$securimage['draw_lines_over_text'] = true;

//是否在文字上增加橫線
$securimage['arc_linethrough'] = false;

//橫線的顏色
$securimage['arc_line_colors']="#8080ff";

低溫烘培 發表在 痞客邦 PIXNET 留言(2) 人氣()


留言列表 (2)

發表留言
  • Chunyu
  • thanks

    I've been struggling with CI and phpCaptcha for a long time and at last I found this. Many thanks!!
  • welcome!

    低溫烘培 於 2010/08/26 06:34 回覆

  • Tongshuai
  • hello, you code looks like not work.
    please look at "$this->CI->session->userdata('securimage_code_value')" in the function validate() under file library/Securimage.php. it does not get the value - the input code.

    my solution is add the following code:
    session_start();
    $_SESSION['securimage_code_value'] = strtolower($this->code);
    into function saveData();

    add
    $this->CI->session->set_userdata('securimage_code_value', $_SESSION['securimage_code_value']);
    into function validate();
    so the value passed to $this->CI->session->userdata('securimage_code_value'), then you post works!
  • =v=我已經在文章開頭補上說明了

    低溫烘培 於 2010/10/12 10:49 回覆