在实时服务器上调用未定义的函数random_bytes()



部署codeignter项目后,我通过电子邮件遇到了忘记密码实现的问题。不过,在本地主机上运行良好。我得到一个错误:消息:调用未定义的函数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' =>"rn",
'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;
}

}

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

尽管这个函数是在PHP 7.0中添加到PHP中的,但»userland实现可用于PHP 5.2到5.6,包括5.2到5.6。

https://www.php.net/manual/en/function.random-bytes.php

相关内容

  • 没有找到相关文章

最新更新