Jump to content
Larry Ullman's Book Forums
Jacques

Supporting Multiple Types Of Administrators

Recommended Posts

I have implemented "multiple types of administrators" as per Chapter 12 and have the following question.

 

What does $SESSION['user_admin'] become in the header.html scrip to support the admin links in the dropdown menu?

 

Any help will be much appreciated.

Share this post


Link to post
Share on other sites

Sorry, I don't have the book in front of me. Can you expand upon how you implemented the multiple types of administrators?

Share this post


Link to post
Share on other sites
                // Validate the password:
		if (password_verify($p, $row['pass'])) { // Correct.
			
			// Create a new session ID to be safe:
			if ($row['type'] === 'user_id') {
				session_regenerate_id(true);
				$_SESSION['user_type'] = $row['type'];
			}
		
			// Store the data in a session:
			$_SESSION['user_id'] = $row['id'];
			$_SESSION['username'] = $row['username'];
		// Validate the password:
		if (password_verify($p, $row['pass'])) { // Correct.
			
			// If the user is an administrator, create a new session ID to be safe:
			if ($row['type'] === 'admin') {
				session_regenerate_id(true);
				$_SESSION['user_admin'] = true;
			}
		
			// Store the data in a session:
			$_SESSION['user_id'] = $row['id'];
			$_SESSION['username'] = $row['username'];

Hi Larry,

 

Thank you for your response.

 

The first block of code is the original from the login.inc.php script, and the second block after multiple types of administrators have been added.

 

In the "users" table the "type" column has been changed to SMALLINT and a table "user_types" with columns "id" and "type" and values (1, 'member'), (50, 'author'), (100, 'editor'), (150, 'admin') created.  

 

I hope it helps.

Share this post


Link to post
Share on other sites

Sorry for the delayed reply! It's not clear what links you want to create, but I'd be inclined to store the user type in a session and then rewrite the toggle in the header file to change what links are shown based upon the actual user type. (This depends, again, on what you actually want to do for the different user types.)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...