Codeigniter消息:调用未定义的函数random_string()

问题描述 投票:1回答:1

我遇到了以下错误遇到了未捕获的异常

类型:错误

消息:调用未定义的函数random_string()

文件名:C:\ xampp \ htdocs \ HerbalCebu \ application \ controllers \ login.php

行号:128

回溯:

文件:C:\ xampp \ htdocs \ HerbalCebu \ index.php行:315功能:require_once,

当我想生成一个随机字符串,它将作为用户的临时密码

这是我的控制器

function forgot_password()
            {
            $this->form_validation->set_rules('emailpass', 'emailpass', 'trim|required');

            if($this->form_validation->run() == FALSE)
            {

            $this->load->view('Login/modal_forgot');
            $this->load->view('CustTemplate/header');
            $this->load->view('Login/Login');
            $this->load->view('CustTemplate/footer');
            }else{
            $password = ('alpha', 8);
            $data = array('password'=>md5($password));
            $this->db->where('email',$this->input->post('emailpass'));

            $this->db->update('users',$data);
            $this->session->set_flashdata('message','here is your new password: <mark>'.$password.'</mark><br> please login now and change the given password');
            redirect(base_url('login'));
            }
            }

            public function check_email($password)
            {
                $email = $this->input->post('emailpass');

                $result = $this->queries_login->get_email($email);

                if($result)
                {
                    return TRUE;
                }
                else
                {
                    $this->form_validation->set_message('Check_email','The email you entered is not on the database');
                    return FALSE;
                }
            }

和模型

public function get_email($email)
        {
            $this->db->select('*');
            $this->db->from('users');
            $this->db->where('email',$email);
            $this->db->limit(1);

            $query = $this->db->get();

            if($query ->num_rows()==1)
            {
                return $query->result();
            }
            else
            {
                return false;
            }
        }
php codeigniter
1个回答
4
投票

我真的没有在你的代码中的任何地方看到它(可能在这里:$password = ('alpha', 8);?),但你应该在通过$this->load->helper('string');调用函数或在application/config/autoload.php中自动加载之前加载帮助器

如果错误仍然存​​在,请确保该文件存在于system/helpers/string_helper.php中。


正如有人使用md5时经常建议的那样 - 你真的不应该使用它(就像在官方文档中推荐的那样):http://php.net/manual/en/function.md5.php

您可以使用password_hash函数验证与password_verifyhttp://php.net/manual/en/function.password-hash.php

© www.soinside.com 2019 - 2024. All rights reserved.