Pregunta

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?" question.

Here's login.php's main code:

<?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.

<?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.

¿Fue útil?

Solución

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

and maybe you don't need the while section.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top