如何解决代码点火器验证码未显示,验证码由守护程序生成
我通过此链接学习如何制作验证码:https://www.codexworld.com/implement-captcha-codeigniter-captcha-helper/。
但是遇到了问题,我使用 sudoers(我的假设问题)启动了 xampp,我的验证码文件夹如下所示:
当我点击f12时,它说没有找到图像,但是当我检查时,文件在那里,但有权限问题,,,
我的代码和我复制的源代码完全一样,
控制器:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Captcha extends CI_Controller
{
function __construct() {
parent::__construct();
// Load session library
$this->load->library('session');
// Load the captcha helper
$this->load->helper('url');
$this->load->helper('captcha');
}
public function index(){
// If captcha form is submitted
if($this->input->post('submit')){
$inputCaptcha = $this->input->post('captcha');
$sessCaptcha = $this->session->userdata('captchaCode');
if($inputCaptcha === $sessCaptcha){
echo 'Captcha code matched.';
}else{
echo 'Captcha code does not match,please try again.';
}
}
// Captcha configuration
$config = array(
'img_path' => 'captcha_images/','img_url' => base_url().'captcha_images/','font_path' => 'system/fonts/texb.ttf','img_width' => '160','img_height' => 50,'word_length' => 8,'font_size' => 18
);
$captcha = create_captcha($config);
// Unset previous captcha and set new captcha word
$this->session->unset_userdata('captchaCode');
$this->session->set_userdata('captchaCode',$captcha['word']);
// Pass captcha image to view
$data['captchaImg'] = $captcha['image'];
// Load the view
$this->load->view('captcha/index',$data);
}
public function refresh(){
// Captcha configuration
$config = array(
'img_path' => './captcha_images/',$captcha['word']);
// Display captcha image
echo $captcha['image'];
}
}
查看:
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- captcha refresh code -->
<script>
$(document).ready(function(){
$('.refreshCaptcha').on('click',function(){
$.get('<?php echo base_url().'captcha/refresh'; ?>',function(data){
$('#captImg').html(data);
});
});
});
</script>
<h4>Submit Captcha Code</h4>
<p id="captImg"><?php echo $captchaImg; ?></p>
<p>Can't read the image? click <a href="javascript:void(0);" class="refreshCaptcha">here</a> to refresh.</p>
<form method="post">
Enter the code :
<input type="text" name="captcha" value=""/>
<input type="submit" name="submit" value="SUBMIT"/>
</form>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。