本文介绍了如何禁用对回调函数的直接访问?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<? if ( ! defined('BASEPATH')) exit();

    class Registration extends CI_Controller {

        public function __construct() {
            parent::__construct();
            $this->load->model('registration_model');
        }

        public function index() {
            $this->load->library('form_validation');

            $this->form_validation->set_rules('email', 'E-mail', 'trim|required|valid_email|callback_email_available');

            if($this->form_validation->run() == FALSE) {
                $this->load->view('registration');
            } else {
                $this->registration_model->add_user();
            }
        }

        # Check E-mail
        public function email_available($email) {
            $this->db->select('email');
            $this->db->where('email', $email);
            $query = $this->db->get('users');
            $result = $query->row();

            if(!empty($result)) {
                $this->form_validation->set_message('email_available', 'This e-mail belongs to another user.');
                return FALSE;
            } else {
                return TRUE;
            }
        }

    }
    ?>

我有一个带有表单验证的注册表单。
而且我有一个回调函数来验证电子邮件的唯一性。

I have a registration form with Form Validation.And I have a callback function to validate email uniqueness.

所有代码都可以正常工作,但是我可以直接访问带有错误的回调函数

All code works fine, but I can directly access to callback function with errors

examle.com/registration/email_available

examle.com/registration/email_available

A PHP Error was encountered
Severity: Warning
Message: Missing argument 1 for Registration::email_available()
Filename: controllers/registration.php

A PHP Error was encountered
Severity: Notice
Message: Undefined variable: email
Filename: controllers/registration.php

如何拒绝直接访问回调函数?

How can I deny direct access to callback function?

推荐答案

您可以在方法名称前添加 _ 拒绝通过HTTP请求进行访问。

You can prefix the method name with an _ to deny access through HTTP request.

这篇关于如何禁用对回调函数的直接访问?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 05:02