Jump to content

Recommended Posts

When a user logs in, I would like to have code that will display certain files if the person is an admin and if they are not, it will display other files.  Something like this is what I am after.  I know that this code is not really checking to see if the user have the admin status, but I would like to create some code that would say if a person have xxxxxx in the admin column of the user table, display the admin navigation, but if they do not, display the normal navigation.  I def know that this is possible, but I am not sure of the right approach.  Is making this a query the right thing to do and if so, how should I go about this?

if (!isset($_SESSION['admin'])) {
include ('./includes/header_admin.html');
} else {
include ('./includes/header.html');
};

 

Thank you.  I look forward to your answers. 

Link to comment
https://forums.phpfreaks.com/topic/55901-solved-login-questions/
Share on other sites

you can Create a field in your database called "authlevel" and then in the header.html you can put in if statements.

if(authlevel == 1) {
include ('./includes/header_admin.html');
}
elseif(authlevel == 0) {
include ('./includes/header.html');
};

That should do it then.

 

Regards ACE

Well, you said you had a column in the database that told whether the user was an admin or not, so why not just use that instead of a session?

 

<?php

//I am assuming you have a session that holds a unique ID for the user that is stored in $user_ID
$query = mysql_query("SELECT rank FROM users WHERE userID='$user_ID'");
$row = mysql_fetch_assoc($query);

if ($row['rank'] == 'admin'){
   echo 'You have admin capabilities!';
   //This is where you would put the links that the admins could see

} else {
   echo "Your not an admin!';
}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.