hiya in my database i have a users table

Create Table Users(

user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
email varchar (40) NOT NULL,
pass CHAR (40) NOT NULL,
first_name varchar (15) NOT NULL,
last_name varchar (30) NOT NULL,
active CHAR (32),
registration_date datertime NOT NULL,
PRIMARY KEY(member_id),
UNIQUE KEY (email),
KEY (email, pass)
)

I want the administrator to be able to login from the same location as the user however when logged in different admin links would appear for the admin pages How would i do this if someone could pleaase let me know i would be greatful

thanks Brims

hiya in my database i have a users table

Create Table Users(

user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
email varchar (40) NOT NULL,
pass CHAR (40) NOT NULL,
first_name varchar (15) NOT NULL,
last_name varchar (30) NOT NULL,
active CHAR (32),
registration_date datertime NOT NULL,
PRIMARY KEY(member_id),
UNIQUE KEY (email),
KEY (email, pass)
)

I want the administrator to be able to login from the same location as the user however when logged in different admin links would appear for the admin pages How would i do this if someone could pleaase let me know i would be greatful

thanks Brims

You'll have to add another field to your users table that associates each user with a user group.

And create a new table called user groups. (Not necessary but good practise)

Example Users Table:

Create Table Users(

user_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
email varchar (40) NOT NULL,
pass CHAR (40) NOT NULL,
first_name varchar (15) NOT NULL,
last_name varchar (30) NOT NULL,
active CHAR (32),
registration_date datertime NOT NULL,
group_id tinyint(3) unsigned NOT NULL default '1',
PRIMARY KEY(member_id),
UNIQUE KEY (email),
KEY (email, pass)
)

Notice the group_id. This associates each user with a user group.

Then you can create a user groups table.

CREATE TABLE user_group (
id tinyint(3) unsigned NOT NULL default '0',
name varchar(50) NOT NULL default '',
PRIMARY KEY (id)
)

Then you can assign groups like "admin", "user" etc.

You login form does not have to change at all.
When a user is logged in, you can just query the db for their user group if you know their user id.

Pseudo Example:

$userid = getUserIdFromSession(); // pseudo function that gets the user id from the users session info

$query = "SELECT u.*, g.* FROM Users AS u, user_group AS g LEFT JOIN user_group ON (u.group_id = g.id) WHERE u.user_id = '$userid' LIMIT 1";

$table_rows = dbQuery($query); // pseudo funciton to query mysql

$user_info = $table_rows[0]; // assuming mysqlQuery returns table rows in an array format, then the user info is in the first array index $table_rows[0]

var_dump($user_info); // debug: take a look at the returned info

$user_group = $user_info['name'];

if ($user_group == 'admin') {
   // user is an admin
  echo 'Admin Links';
} else {
  // user is not an admin
  echo 'User links';
}

}

This will return the User information Merged with the user_group.
You can then decide if the user is an admin based on the returned group.

This article has been dead for over six months. Start a new discussion instead.