简体   繁体   English

登录脚本不起作用(重定向)

[英]Login script not working (redirection)

SO, what I've been trying to do is set up a login system. 因此,我一直试图做的是建立一个登录系统。 I had the system working, but then I needed to add the menu buttons. 我的系统正常运行,但随后需要添加菜单按钮。 For some weird reason, that broke it... all the menu is, is a simple "is the session value 1?" 由于某种奇怪的原因,它崩溃了……所有菜单都是一个简单的“会话值是否为1?” question. 题。

Here's login.php's main code: 这是login.php的主要代码:

<?php
    session_start();
    $errmsg='';
    if($_POST['email']&&$_POST['password']){
        $_SESSION['email']=$_POST['email'];
        $_SESSION['password']=$_POST['password'];
        header("Location: validate.php");
    }
    if($_SESSION['vcode']){
        $code=$_SESSION['$vcode'];
        if($code==4){
            $errmsg="Invalid login details. Please try again.";
        }else{
            $errmsg='';
        }
        $_SESSION['vcode']==0;
    }
?>

Then, it redirects to validate.php. 然后,它重定向到validate.php。

<?php
    session_start();
    include '/home/raymonf2/mysqlincludeprs.php';
    $email=$_SESSION['email'];
    $pw=hash('ripemd160', $_SESSION['password']);
    $status=0; // Original value is 0; not validated (yet?)
    $sql = 'SELECT * FROM users WHERE username = \'' . $email . '\' AND password = \'' . $pw . '\';';

    if(!$result = $db->query($sql)){
        die('There was an error running the query [' . $db->error . ']. Sorry!');
    }
    while($row = $result->fetch_assoc()){
            if($result->num_rows>0){
                $status==1;
            }
    }

    if($status==1){
    // Back to homepage if okay.
        unset($_SESSION['email']);
        unset($_SESSION['password']);
        $_SESSION['loggedin']==1;
        header("Location: /index.php");
        die("<a href=\"/\">Click here if not automatically redirected to index.</a>");
    }else{
        $_SESSION['loggedin']==0;
        $_SESSION['vcode']==4;
        header("Location: login.php");
    }
?>

Any suggestions would be appreciated. 任何建议,将不胜感激。

The problem is that the login page directs to validate, and then back to login without an error message. 问题在于登录页面指示进行验证,然后返回登录而没有错误消息。

if($result->num_rows>0){
            $status==1;//should be $status = 1;
        }

and maybe you don't need the while section. 也许您不需要while部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM