Your user DB should have a userlevel field which can be stored as bits, e.g.
0 = no activated
1 = regular user
2 = moderator
4 = admin
8 = superadmin
An user with admin rights should then have all the rights of admin and below, so
admin userlevel = sum of all = 1 + 2 + 4 = 7
suepradmin = 1 + 2 + 4 + 8 = 15
You then check using the bitwise operator:
if($row['userlevel'] & 4){
$admin = true;
}
Or something like that.
You could have a simpler setup with just an admin field (0 or 1).
diafol
Keep Smiling
10,668 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,514
Skill Endorsements: 57
Quick suggestion: when login is true I prefer to set a session which enables users rights. So, at least, I can stop bugging the database for that. Otherwise I will have an extra query for each reserved page and each user logged. Bye :)
cereal
Veteran Poster
1,146 posts since Aug 2007
Reputation Points: 344
Solved Threads: 223
Skill Endorsements: 22
THis assumes an user is already set. WHat happens if the user is not set and the user tries to access the page? You'll probably get an error in the mysql. SO you have to check that session user var is set as opposed to taking it for granted.
<?php
//start session and get username variable
session_start();
if(isset($_SESSION['user']) && isset($_SESSION['userlevel'])){
$user = $_SESSION['user'];
if ($_SESSION['userlevel' == 1) {
header('Location: Blog-admin-area.php');
exit();
}else{
header('Location: Blog.php');
exit();
}
}else{
//redirect to default page (index.php?) with header()
}
?>
This applies cereal's thoughts about storing userlevel in session data too (on login) - no need for a db call.
However, I don't know the purpose of this file. I would assume that this would go at the top of the Blog-admin-area.php file itself, modified to this:
<?php
//start session and get username variable
session_start();
if(!isset($_SESSION['user']) || !isset($_SESSION['userlevel']) || $_SESSION['userlevel'] != 1){
header('Location: Blog.php');
}
?>
diafol
Keep Smiling
10,668 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,514
Skill Endorsements: 57
place a ;at the end of line 11
diafol
Keep Smiling
10,668 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,514
Skill Endorsements: 57
You need to add exit(); after every header(...);
In addition, why is count = 0? Surely if you want success, it should be > 0?
Also 'user_level' is not a variable. You haven't even extracted it from the $result resource.
Use mysql_fetch_array() or similar.
diafol
Keep Smiling
10,668 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,514
Skill Endorsements: 57