Session in login page problem.
Posted: Sun Feb 24, 2008 7:17 pm
Im new to php, and im learning as i go along and ive decided to make a game with a login which ID's if a user is a admin or banned or what not.
Whilst doing this ive ran into a problem with using sessions to identify if the user is banned or is an admin..
The code ive got so far is this to make the sessions on the login page..
On the overview page ive got a IF to check if hes banned or not, if he is he gets an error, if not the page loads.
and if hes not banned and is an admin it displays an extra link in the navigation..
This code doesn't work at all lol, but as i said, im new and im only playing around. Currently, when i try to log in with a user which is not banned i get the ban message even though i shouldnt :S
Most likley ive gone around it all the totally wrong way.
Anyway help will be appreciated
Whilst doing this ive ran into a problem with using sessions to identify if the user is banned or is an admin..
The code ive got so far is this to make the sessions on the login page..
Code: Select all
$query="SELECT * FROM game_accounts";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$UserID=mysql_result($result,$i,"UserID");
$Admin=mysql_result($result,$i,"admin");
$Banned=mysql_result($result,$i,"banned");
$i++;
}
$_SESSION['UserID'] = $UserID; // store session data
$_SESSION['IsAdmin'] = $Admin;
$_SESSION['IsBanned'] = $Banned;
//then redirect them to the members area
header("Location: overview.php");Code: Select all
<?php
session_start();
if ($_SESSION['IsBanned']=1){
echo ('<center><font color="red">Your account has been banned</font><br><a href="logout.php">Back</a></center>');
}
else {
}Code: Select all
<link href="styles/style.css" rel="stylesheet" type="text/css" />
<center>
<a href="overview.php">Overview</a> -
<a href="units.php">Units</a> -
<a href="profile.php">Profile</a> -
<?php
if ($_SESSION['IsAdmin']=1){
echo ('<a href="admin.php">Admin Panel</a> - ');
echo ('<a href="logout.php">Logout</a>');
}
else{
echo ('<a href="logout.php">Logout</a>');
}
?>
</center>Most likley ive gone around it all the totally wrong way.
Anyway help will be appreciated