dongmou1964 2013-08-22 00:57
浏览 140
已采纳

CodeIgniter中的Captcha代码区分大小写

I use CI in one of my application and here I implement CI captcha. I use random_string('alnum', 8) to create upper and lower case combination captcha code. Here user must neede to write captcha code which is exactly shown in the image; which is casesensetive. Here I need to add some trick; I want to remove the casesensivity which is user can able to filled captcha code with uppercase or with lowercase as he shown in the image.

Here is my captcha implemented code -

$cap_word = random_string('alnum', 8);

$options = array(
 'word'   => $cap_word,
 'img_path'  => './captcha/',
 'img_url'   => base_url() . 'captcha/',
 'font_path'    => './fonts/custom.ttf',
 'img_width'    => 150,
 'img_height' => 30,
 'expiration' => 7200
 );

$cap = create_captcha($options);

And here is my callback function for checking -

public function validate_captcha_code() {

    $cap = $this->input->post('captcha_code');
    if($cap != $cap_word) {
    $this->form_validation->set_message('validate_captcha_code', 'Wrong captcha code, Please try again.');
        return false;
    }else{
        return true;
    }
}
  • 写回答

3条回答 默认 最新

  • donglu3087 2013-08-22 01:04
    关注

    You just update your validate function like that -

       public function validate_captcha_code() {
    
        $cap = $this->input->post('captcha_code');
    
            if(strtolower($cap) != strtolower($cap_word) || strtoupper($cap) != strtoupper($cap_word)) {
                $this->form_validation->set_message('validate_captcha_code', 'Wrong captcha code, Please try again.');
                return false;
            }else{
                return true;
            }
    }
    

    Try this hope this works in both upper and lowercase . And let me know what's going on.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部