Php 在live server上调用未定义的函数random_bytes()

Php 在live server上调用未定义的函数random_bytes(),php,codeigniter,Php,Codeigniter,部署Codeigner项目后,我遇到了通过电子邮件实现忘记密码的问题。不过,在本地主机上,它运行得很好。 我得到一个错误: 消息:调用未定义函数random_bytes() 这是我的控制器功能 public function forgotPassword () { $this->form_validation->set_rules("email", "Email", "trim|required"); if($this->form_validat

部署Codeigner项目后,我遇到了通过电子邮件实现忘记密码的问题。不过,在本地主机上,它运行得很好。 我得到一个错误: 消息:调用未定义函数random_bytes() 这是我的控制器功能

public function forgotPassword () {
        $this->form_validation->set_rules("email", "Email", "trim|required");
        if($this->form_validation->run() == false) {
            $this->load->view('forgotPassword');
        }else {
            $email = $this->input->post('email');
            $user=$this->db->get_where('users', array('email'=>$email, 'is_active'=>1))->row_array();
            if($user) {
                $token = base64_encode(random_bytes(32));
                $user_token=array(
                    'email'=>$email,
                    'token'=>$token,
                    'date_created'=>time()
                );
                $this->db->insert('user_token', $user_token);
                $this->load->model('Register_model', 'reg');
                $this->reg->sendEmail($token, 'forgot');
                $this->session->set_flashdata("message", "Check your email to reset your password");
                redirect("auth/forgotPassword");

            }else{
                $this->session->set_flashdata("message", "Email doesn't exist or is not activated");
                redirect("auth/forgotPassword");
            }
        }
    }
模型功能*

public function sendEmail($token, $type) {
        $config = array(
            'protocol'=>'smtp',
            'smtp_host'=>'ssl://smtp.googlemail.com',
            'smtp_user'=>'***',
            'smtp_pass'=>'***',
            'smtp_port'=> '465',
            'mailtype'=> 'html',
            'charset'=> 'iso-8859-1',
            'newline' =>"\r\n",
            'wordwrap' => TRUE
        );

        $this->load->library('email', $config);
        $this->email->from('***', 'Web app');
        $this->email->to($this->input->post('email'));
        if($type == 'verify') {
            $this->email->subject('Account verification');
            $this->email->message('Click here to verify account: <a href="' .
                base_url() . 'index.php/auth/verify?email=' . $this->input->post('email') .
                '&token=' . urlencode($token) . '">Activate</a>');
        }
        elseif ($type == 'forgot') {
            $this->email->subject('Reset password');
            $this->email->message('Click here to reset your password: <a href="' .
                base_url() . 'index.php/auth/resetpassword?email=' . $this->input->post('email') .
                '&token=' . urlencode($token) . '">Reset</a>');
        }

        //$this->email->send();
        if($this->email->send()) {
            return true;
        }else {
            echo $this->email->print_debugger();
            die;
        }


    }
公共函数sendmail($token,$type){
$config=array(
“协议”=>“smtp”,
'smtp_主机'=>'ssl://smtp.googlemail.com',
'smtp_用户'=>'***',
'smtp_pass'=>'***',
“smtp_端口”=>“465”,
“邮件类型”=>“html”,
“字符集”=>“iso-8859-1”,
'换行符'=>“\r\n”,
'wordwrap'=>TRUE
);
$this->load->library('email',$config);
$this->email->from('***','webapp');
$this->email->to($this->input->post('email');
如果($type=='verify'){
$this->email->subject(‘帐户验证’);
$this->email->message('单击此处验证帐户:');
}
elseif($type==‘遗忘’){
$this->email->subject('Reset password');
$this->email->message('单击此处重置密码:');
}
//$this->email->send();
如果($this->email->send()){
返回true;
}否则{
echo$this->email->print_debugger();
死亡
}
}

检查本地计算机和远程服务器上的版本。 因为在文档中:

虽然该函数是在PHP7.0中添加到PHP中的,但PHP5.2到5.6(含5.6)中提供了»userland实现


您在服务器上使用的是什么版本的PHP
random_bytes
是在PHP7中引入的。我是codeigniter的新手,这是我的第一次部署。我想我可以在app.yaml中检查php版本?它说“runtime:php55 api_version:1”不,PHP版本是服务器上的环境,而不是代码中的环境。您可以通过在服务器上创建一个文件来检查它,该文件的内容为
yhank以获取帮助。我在GoogleShell中输入了php-v。它说PHP7.2.29-1+0~20200320.39+debian9~1.gbp513c2e谷歌搜索错误的第一个结果产生了重复的结果。在服务器上,它说PHP7.2.29-1+0~20200320.39+debian9~1.gbp513c2e。。。。。