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
https://forums.phpfreaks.com/topic/12696-help-with-redirection-and-login/
Share on other sites

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.