php 在CodeIgniter网站中添加表单中的Captcha:https://www.cloudways.com/blog/captcha-in-codeigniter/
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 在CodeIgniter网站中添加表单中的Captcha:https://www.cloudways.com/blog/captcha-in-codeigniter/相关的知识,希望对你有一定的参考价值。
<?php
defined('BASEPATH') OR exit('your exit message');
class Captcha extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('captcha');
}
public function index()
{
if ($this->input->post('submit')) {
$captcha_insert = $this->input->post('captcha');
$contain_sess_captcha = $this->session->userdata('valuecaptchaCode');
if ($captcha_insert === $contain_sess_captcha) {
echo 'Success';
} else {
echo 'Failure';
}
}
$config = array(
'img_url' => base_url() . 'image_for_captcha/',
'img_path' => 'image_for_captcha/',
'img_height' => 45,
'word_length' => 5,
'img_width' => '45',
'font_size' => 10
);
$captcha = create_captcha($config);
$this->session->unset_userdata('valuecaptchaCode');
$this->session->set_userdata('valuecaptchaCode', $captcha['word']);
$data['captchaImg'] = $captcha['image'];
$this->load->view('captcha/index', $data);
}
public function refresh()
{
$config = array(
'img_url' => base_url() . 'image_for_captcha/',
'img_path' => 'image_for_captcha/',
'img_height' => 45,
'word_length' => 5,
'img_width' => '45',
'font_size' => 10
);
$captcha = create_captcha($config);
$this->session->unset_userdata('valuecaptchaCode');
$this->session->set_userdata('valuecaptchaCode', $captcha['word']);
echo $captcha['image'];
}
}
以上是关于php 在CodeIgniter网站中添加表单中的Captcha:https://www.cloudways.com/blog/captcha-in-codeigniter/的主要内容,如果未能解决你的问题,请参考以下文章
Codeigniter 表单打开如何删除 index.php
Codeigniter 和 PHP - 强制 404?
使用 CODEIGNITER 的动态 php 网站
Codeigniter 表单发布数据为空
Codeigniter 表单通过文件上传提交
PHP CodeIgniter 加载视图问题,加载完整路径两次