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

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 09: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条)

报告相同问题?

悬赏问题

  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题