adding an admin function to my login system

So I want to add something to my code, an admin type of thing. In the table i added a admin column, it’s type enum with 0 and 1, and the set is as defined 0. I want it so that it checks if a user is admin (1) and when they log in it says You are now logged in as admin$username, else is just gives the normal 'You are now logged in as $username

my script: http://pastebin.com/yy8f7PjQ

any help? I want it to check if $user is also admin then give them the message when they press log in

Well, not really sure what your question is…

But, you load in the user’s info and place it into an array named $user. Just pull out the col (field) that you
stored the info into. If it is ‘admin’ then, you would do something like:

if ($user[‘admin’]=0) {
do something here for normal users…
echo "You are logged in as " . $username;
} else {
do something here for admins…
echo "You are logged in as and ADMIN: " . $username;
}

Normally you would do everything for the admin, but, display the special admin stuff just for admin’s only.

Is that what you are asking?

This is what I do for my edit page:
[php]if (isset($id)) {
$record = $blog->readSingleRecord($id);
if ($user->id === $record->creator_id || $user->security_level === ‘sysop’) {
$title = $record->title;
$content = $record->content;
} else {
header(“Location: index.php”);
exit();
}
} else {
header(“Location: index.php”);
exit();
}[/php]

I obviously give the original poster editing privileges, but I also give anyone with sysop level (in this case me) editing privileges. There are many other administration functions you can giva a person with a certain level access to. However you just have to becareful you don’t accidentally give a person with a lower access the privilege. It’s gets pretty obvious who is just a member or who is an administrator when logged in, so in my opinion it’s not really necessary to point it out; however, if it’s a forum or chatroom it might be nice to point it out to people who use the website.

[member=57087]Strider64[/member], you would do better to use an integer for the access level rather than char or varchar and another column for the actual text description if you need to display it somewhere.

Sponsor our Newsletter | Privacy Policy | Terms of Service