【发布时间】:2019-05-27 06:23:33
【问题描述】:
当我输入错误的电子邮件时,我用 Codeigniter 编写的代码出现以下错误。
遇到 PHP 错误 严重性:通知
消息:试图获取非对象的属性“电子邮件”
文件名:controllers/forms.php
行号:26
回溯:
文件: E:\Software\XAMPP\xampp\htdocs\ciauth\application\controllers\forms.php 行:26 函数:_error_handler
文件:E:\Software\XAMPP\xampp\htdocs\ciauth\index.php 行:315 函数:require_once
下面是控制器
<?php
class Forms extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->database();
$this->load->library('session');
$this->load->helper('url');
$this->load->model('user_model', 'auth');
}
public function forgot_pass()
{
if($this->input->post('forgot_pass'))
{
$email=$this->input->post('email');
$this->load->model('user_model', 'auth');
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'E-mail', 'required');
if ($this->form_validation->run() == TRUE) {
$que=$this->db->query("select password,email from users where email='$email'");
$row=$que->row();
$user_email=$row->email;
if((!strcmp($email, $user_email)))
{
$pass=$row->password;
$to = $user_email;
$subject = "Password";
$txt = "Your password is $pass .";
$headers = "From: user@testdomain.com" . "\r\n" . "CC: hamza_zon@outlook.com ";
mail($to,$subject,$txt,$headers);
$this->load->view('user/header');
$this->load->view('user/confirm');
$this->load->view('user/footer');
}
else{
$data['error']="Invalid Email ID !";
}
}
else{
$data['error']="Email ID is required !";
}
}
$this->load->view('user/header');
$this->load->view('user/forgot_pass',@$data);
$this->load->view('user/footer');
}
}
?>
【问题讨论】:
-
那么如何处理邮件不在表格中的情况呢?您的代码假定电子邮件存在。
-
我该怎么做?
-
看起来好像您在数据库中存储纯文本密码 - 这不是一个好主意!尝试寻找更好的方法来帮助忘记密码的用户,而不是这样。
标签: php codeigniter validation