Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 试图获得财产';密码';非对象_Php - Fatal编程技术网

Php 试图获得财产';密码';非对象

Php 试图获得财产';密码';非对象,php,Php,我有一个错误代码的问题,当我故意登录失败时,它会在上面的标题中弹出错误 if ($password == $user->password ) { $_SESSION['id'] = $user->u_id; $_SESSION['name'] = $user->u_name; header("Location: http://website/index/main.php"); } else{ ec

我有一个错误代码的问题,当我故意登录失败时,它会在上面的标题中弹出错误

    if ($password == $user->password ) {
        $_SESSION['id'] = $user->u_id;
        $_SESSION['name'] = $user->u_name;

        header("Location: http://website/index/main.php");
    } else{
        echo"fail";
    }

那我该怎么办?我想改变
echo“fail”
标题(“位置:http://website/index/login.php)
但这似乎完全错了。有什么建议吗?

在从$user对象获取密码之前,请使用isset方法检查密码是否为空

 if(isset($user)){
 if ($password == $user->password ) {
    $_SESSION['id'] = $user->u_id;
    $_SESSION['name'] = $user->u_name;

    header("Location: http://website/index/main.php");
  } else{
    //back to login page using header
 }
 }
else
{
//back to login page using header
}

您的代码将被截断,以便我们确定其余部分,但如果我不得不猜测,
$user
将不会被设置,如果用户名/电子邮件不存在。但是是的,如果你的系统中没有用户名/电子邮件,不要让他们进入:D将他们返回到登录屏幕,如果密码错误,也不要提示他们,只需重新重定向他们,用户名/密码不存在啊,从我找到的其他解决方案,它说它在数据库中不包含以下数据,所以它显示了错误,我想知道的是是否存在拒绝代码,而是将它们引导回登录页面在您获取$user对象的密码之前,使用isset检查它是否为null,如果(isset($user)){//获取密码并检查是否相等}否则//返回登录页面。我很乐意帮助:-)