Jump to content
Larry Ullman's Book Forums

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.

Link to comment
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.

Link to comment
Share on other sites

  • 2 weeks later...

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.)

Link to comment
Share on other sites

 Share

×
×
  • Create New...