dougehe2022 2018-03-04 08:49
浏览 118
已采纳

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

I've face this following error An uncaught Exception was encountered

Type: Error

Message: Call to undefined function random_string()

Filename: C:\xampp\htdocs\HerbalCebu\application\controllers\login.php

Line Number: 128

Backtrace:

File: C:\xampp\htdocs\HerbalCebu\index.php Line: 315 Function: require_once,

When i want to generate an random strings where it will place as temporary password for a user

And here's my Controller

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;
                }
            }

And the model

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;
            }
        }
  • 写回答

1条回答 默认 最新

  • donglu5000 2018-03-04 08:57
    关注

    I don't really see it in use anywhere in your code (maybe here: $password = ('alpha', 8);?), but you should load the helper before calling the function via $this->load->helper('string'); or autoloading it in application/config/autoload.php

    If the error still persists make sure the file exists in system/helpers/string_helper.php.


    As is constantly suggested whenever someone uses md5 - you really shouldn't use it (as even recommended in the offical docs): http://php.net/manual/en/function.md5.php

    You could use the password_hash function verify with password_verify. http://php.net/manual/en/function.password-hash.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助