PDA

View Full Version : user level/different pages


rattlsnak
09-05-2008, 01:04 AM
OK, I had this working on another site, but for some reason it wont work on the one I'm currently working on.

I need certain users to be directed to one page, and others to another.

I have this:

A login page with a form, that submits to a check page:

$query="SELECT * FROM userdatabase WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($query);
$rowAccount=mysql_fetch_array($result);


if($rowAccount){
session_start();
$_SESSION['user'] = $rowAccount['user'];
$_SESSION['username'] = $rowAccount['username'];
$_SESSION['email'] = $rowAccount['email'];
$_SESSION['level'] = $rowaccount['level'];

header("location:homelevel1.php");
}
else {
header("location:loginerror.php");
}

Which if found a valid user, goes to homelevel1.php, and on that page I have this at the top:

session_start();
if (! isset($_SESSION['user'])){
header("location:login.php");
}
elseif ($_SESSION['level'] == '2')
{header ("location:homelevel2.php");
}


But no matter who logs in, it goes to the homelevel1 page.
I tried changing the session id to 'level', and changing the else if, to just an if statement, but niether works.

Should I redirect it from the first check page? How?

OK, what i am doing wrong?

rattlsnak
09-05-2008, 01:27 AM
SON of a @#$%^& !

OK, I got it,...

$_SESSION['email'] = $rowAccount['email'];
$_SESSION['level'] = $rowaccount['level'];


I'm better now,.... :)

davidj
09-05-2008, 05:31 AM
im gona smack the back of your legs if you dont use code tags