如何在 PHP codeigniter 框架中修复 "Undefined property: Register::$encrypt"
How to fix "Undefined property: Register::$encrypt" in PHP codeigniter framework
当我在 CodeIgniter 中提交表单时,我收到此错误消息:未定义 属性:Register::$encrypt。我想散列密码,这就是我使用加密的原因。
我尝试在 autoload.php 中包含加密库,但仍然弹出另一个错误。
这是弹出错误的地方。
函数验证(){
$this->form_validation->set_rules('user_name','Name','required|trim');
$this->form_validation->set_rules('user_email','Email Address','required|trim|valid_email|is_unique[codeigniter_register.email]');
$this->form_validation->set_rules('user_password','Password','required|trim');
if($this->form_validation->run()){
$verification_key=md5(rand());
$encrypted_password = $this->encrypt->encode($this->input->post('user_password'));
$data = array(
'name' => $this->input->post('user_name'),
'email' => $this->input->post('user_email'),
'password' => $encrypted_password,
'verification_key' => $verification_key
);
$id=$this->register_model->insert($data);
if($id > 0){
$subject='Please verify email for login';
$message="
<p>Hi".$this->input->post('user_name')."</p>
<p>Verify your email for login to this system. Click this <a href='".base_url()."register/verify_email/".$verification_key."'>link</a>.</p>
<p>Use this link to log in in to this system.</p>
<p>Thanks You.</p>
";
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtpout.secureserver.net',
'smtp_port' => 80,
'smtp_user' => 'root',
'smtp_pass' => 'root',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' =>TRUE
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('info@icode.info');
$this->email->to($this->input->post('user_email'));
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send()){
$this->session->set_flashdata('message','Check in your email for verification mail');
redirect('register');
}
}
}
else{
$this->index();
}
我希望在提交表单后发出警报或将我在表单中填写的数据发送到数据库,
加载加密库
$this->load->library('encryption');
$encrypted_password = $this->encrypt->encode($this->input->post('user_password'));
https://www.codeigniter.com/user_guide/libraries/encryption.html
Once loaded, the Encryption library object will be available using:
$this->encryption
更新:
正如您提到的在构造函数中加载它,我又看了一眼:
好像是拼写错误
$this->load->library('encryption');
...
$this->encrypt->encode($this->input->post('user_password'));
而不是
$this->load->library('encryption');
...
$this->encryption->encode($this->input->post('user_password'));
在文档中也是这样呈现的
$ciphertext = $this->encryption->encrypt($plain_text);
一个简单的错误,我看了几分钟也看到了。如果可以避免,我从不打字,我 copy/paste 一切。主要是因为我的拼写和东西不好(阅读障碍)但是它可以避免这样的一些问题......大声笑
很高兴我们为您整理好了!
当我在 CodeIgniter 中提交表单时,我收到此错误消息:未定义 属性:Register::$encrypt。我想散列密码,这就是我使用加密的原因。
我尝试在 autoload.php 中包含加密库,但仍然弹出另一个错误。
这是弹出错误的地方。
函数验证(){
$this->form_validation->set_rules('user_name','Name','required|trim');
$this->form_validation->set_rules('user_email','Email Address','required|trim|valid_email|is_unique[codeigniter_register.email]');
$this->form_validation->set_rules('user_password','Password','required|trim');
if($this->form_validation->run()){
$verification_key=md5(rand());
$encrypted_password = $this->encrypt->encode($this->input->post('user_password'));
$data = array(
'name' => $this->input->post('user_name'),
'email' => $this->input->post('user_email'),
'password' => $encrypted_password,
'verification_key' => $verification_key
);
$id=$this->register_model->insert($data);
if($id > 0){
$subject='Please verify email for login';
$message="
<p>Hi".$this->input->post('user_name')."</p>
<p>Verify your email for login to this system. Click this <a href='".base_url()."register/verify_email/".$verification_key."'>link</a>.</p>
<p>Use this link to log in in to this system.</p>
<p>Thanks You.</p>
";
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'smtpout.secureserver.net',
'smtp_port' => 80,
'smtp_user' => 'root',
'smtp_pass' => 'root',
'mailtype' => 'html',
'charset' => 'iso-8859-1',
'wordwrap' =>TRUE
);
$this->load->library('email',$config);
$this->email->set_newline("\r\n");
$this->email->from('info@icode.info');
$this->email->to($this->input->post('user_email'));
$this->email->subject($subject);
$this->email->message($message);
if($this->email->send()){
$this->session->set_flashdata('message','Check in your email for verification mail');
redirect('register');
}
}
}
else{
$this->index();
}
我希望在提交表单后发出警报或将我在表单中填写的数据发送到数据库,
加载加密库
$this->load->library('encryption');
$encrypted_password = $this->encrypt->encode($this->input->post('user_password'));
https://www.codeigniter.com/user_guide/libraries/encryption.html
Once loaded, the Encryption library object will be available using:
$this->encryption
更新:
正如您提到的在构造函数中加载它,我又看了一眼:
好像是拼写错误
$this->load->library('encryption');
...
$this->encrypt->encode($this->input->post('user_password'));
而不是
$this->load->library('encryption');
...
$this->encryption->encode($this->input->post('user_password'));
在文档中也是这样呈现的
$ciphertext = $this->encryption->encrypt($plain_text);
一个简单的错误,我看了几分钟也看到了。如果可以避免,我从不打字,我 copy/paste 一切。主要是因为我的拼写和东西不好(阅读障碍)但是它可以避免这样的一些问题......大声笑
很高兴我们为您整理好了!