Jump to content

Help with redirection and login


Ameslee

Recommended Posts

Hey hope someone can help. I have at the moment a website that is connected to a database. I have created a login area, which connects to maintenance pages. I have user levels, so if someone logs in and there username so happens to be Admin or Owner, there allowed in with different access abilities. but i have one problem at the moment, i can login, but i can when i go to access any of the maintenace pages it throughs me back out to the homepage.

Here is my code that i have used. please help.

[code]
<?php
session_start();
header("Cache-control: no-cache");


//this includes the database connection
include("database.inc");


//Get the user's input from the form

    $username = trim($_POST['user']);


//Get the user's input from the form
    
    $password = trim($_POST['pass']);



//check username and password are correct
$users_query = "SELECT * FROM user where username = '$user' AND password = '$pass'";
//echo $users_query;
$mysql_result=mysql_query($users_query,$conn);

$row=mysql_fetch_row($mysql_result);



//if valid user doesnt exist set the error message and redirect to badlogin page
if ($username=="")
{
//echo "nooo";
header("Location: ");
}
else
{
//if valid user exists set all the session variables
//$row is the record, [3] is the 3rd element(field) in the array

$_SESSION['Level']=$username[5];
$_SESSION['username']=$username[1];


//redirect to the page you want to allow the user to access
//echo "yesss";
header(" ");

}
?>[/code]

The security code:
[code]
<?php
session_start();
if ($_session['level'] != "Admin" && $_session['level'] != "Owner" }
{
    header("Location: login.php");
}

?>[/code]

Any help is apprieciated, thanks
Link to comment
Share on other sites

[code]if ($_session['level'] != "Admin" && $_session['level'] != "Owner" } [/code]

Should be $_SESSION not $_session, but the line ending } should be a )

[code]if ($_SESSION['level'] != "Admin" && $_SESSION['level'] != "Owner" ) [/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.