Jump to content

Problem with session control not being created


matio

Recommended Posts

Hi everyone, I'm trying to make a login page, I have two files -- that are important to this post:

1) login.php:

<?php

require_once("include/db.php");
session_start();

$user = $_POST['user'];
$pass = $_POST['password'];

if (user && pass){
        $con = db_connect();

        $sha = sha1($pass);
        $result = $con->query("select * from users where username='$user' and passwrd='$sha';");
        if ($result->num_rows == 0){
                echo '<div style="width:790px;min-height:700px;margin:auto;background:white">';
                include_once("include/header.php");
                include_once("include/navbar.php");
                echo 'Wrong username or password -- please try again';
                echo $sha;
                exit;
        }


        $_SESSION['valid_user'] = $user;

        if($_SESSION['valid_user'] == "admin"){
                header("Location: admin.php");
                exit;
        }

        header("Location: member.php");
        exit;
}else{
        include_once("include/header.php");
        include_once("include/navbar.php");
        echo 'Please go back and fill in all required details';
}
?>

 

2) admin.php:

<?php
require_once("include/db.php");

echo '<div style="width:790px;min-height:700px;margin:auto;background:white">';
include_once("include/header.php");
include_once("include/navbar.php");

echo '<br />';

if($_SESSION['valid_user'] == "admin"){

}else{
        echo 'You cannot view this page -- please login';
}

?>

I login as admin and get redirected to admin.php -- but when I get there it says that I cannot view this page. Don't know why this doesn't work seen as I'm using the same 'if' conditions...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.