登录php脚本不允许登录

时间:2016-01-25 22:19:01

标签: php mysql login

我已经创建了一个登录系统,但是当我登录时,即使它是测试用户并且细节正确,也说电子邮件或密码不正确。也许它与数据库不匹配,我一遍又一遍地检查。我似乎无法找到问题所在。任何帮助深表感谢。

PHP:     

if(isset($_SESSION['user'])!="")
{
header("Location: index-user.php");
}

if(isset($_POST['btn-login']))
{
$email = mysql_real_escape_string($_POST['email']);
$upass = mysql_real_escape_string($_POST['pass']);

$email = trim($email);
$upass = trim($upass);

$res=mysql_query("SELECT user_id, user_name, user_pass FROM users WHERE user_email='$email'");
$row=mysql_fetch_array($res);

$count = mysql_num_rows($res); // if uname/pass correct it returns must be 1 row

if($count == 1 && $row['user_pass']==md5($upass))
{
    $_SESSION['user_name'] = $row['user_id'];
    header("Location: index-user.php");
}
else
{
    ?>
<script>alert('Email or password invalid.');</script>
    <?php
}

}
?>

HTML:

<input class="loginmodal-input" type="text" name="email" placeholder="Email" required>
<input class="loginmodal-input" type="password" name="upass" placeholder="Password" required>
<button type="submit" name="btn-login" id="login-btn" class="login btn-block loginmodal-submit">Login</button>
<button class="login-btn-2 btn btn-lg btn-block" type="button" aria-label="Close" value="Cancel" data-dismiss="modal"> Cancel</button>

MySQL信息: 用户身份 用户名 USER_EMAIL user_pass

1 个答案:

答案 0 :(得分:2)

这一行中的条件:

if(isset($_SESSION['user'])!="")
如果True已设置,

结果$_SESSION['user'],如果它为空,则为issetTrue返回布尔值,如果设置了变量则设置为False,否则为False。 ampty字符串被评估为$_SESSION['user']。因此,如果未设置if( False != False ),则代码会评估header("Location")

此外,您必须在调用if( !isset( $_SESSION['user'] ) ) { header( "Location: index-user.php" ); die(); } (...) 后结束php脚本:

    lyrics.addGestureRecognizer(UITapGestureRecognizer(target: self, action: "show_fdw_bck"))

    func show_fdw_bck () {
    print("screen tapped")
    if SongMgr.settings2 == false {
        fwdappear.hidden = true
        bckappear.hidden = true
        navigationController?.navigationBarHidden = true
        navigationController?.setToolbarHidden(true, animated: false)
        //lyrics.frame = CGRect(x: 10, y: 80, width: self.view.frame.size.width - 20, height: self.view.frame.size.width)
        SongMgr.settings2 = true
    } else {
        fwdappear.hidden = false
        bckappear.hidden = false
        navigationController?.navigationBarHidden = false
        navigationController?.setToolbarHidden(false, animated: false)
        //lyrics.frame = CGRect(x: 10, y: 0, width: self.view.frame.size.width - 20, height: self.view.frame.size.width)

        SongMgr.settings2 = false
    }

}