Php CodeIgniter中的验证码区分大小写
我在我的一个应用程序中使用CI,并在这里实现CI验证码。我使用Php CodeIgniter中的验证码区分大小写,php,codeigniter,captcha,case-sensitive,Php,Codeigniter,Captcha,Case Sensitive,我在我的一个应用程序中使用CI,并在这里实现CI验证码。我使用随机字符串('alnum',8)创建大写和小写组合验证码。在这里,用户必须要写验证码,这是确切地显示在图像;这是非常敏感的。这里我需要添加一些技巧;我想删除casesensivity,这是用户可以填写大写或小写的验证码,如图所示 这是我的验证码实现代码- $cap_word = random_string('alnum', 8); $options = array( 'word' => $cap_word, 'img_
随机字符串('alnum',8)
创建大写和小写组合验证码。在这里,用户必须要写验证码,这是确切地显示在图像;这是非常敏感的。这里我需要添加一些技巧;我想删除casesensivity,这是用户可以填写大写或小写的验证码,如图所示
这是我的验证码实现代码-
$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);
这是我的回调函数,用于检查-
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;
}
}
将验证功能更新为: 我用过这个
public function validate_captcha_code() {
$cap = strtolower($this->input->post('captcha_code'));
if($cap != strtolower($cap_word)) {
$this->form_validation->set_message('validate_captcha_code', 'Wrong captcha code, Please try again.');
return false;
}else{
return true;
}
}
看看PHP的函数。您只需像这样更新验证函数-
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;
}
}
试试这个,希望它能用大小写。告诉我发生了什么事。谢谢你的帮助;这只适用于小写字母。在这里,用户只能填写小写字母。但我需要用户能够同时填写大写或小写字母。@follett这将消除敏感性,因为在比较时,任何内容都将转换为小写。