Jump to content
Larry Ullman's Book Forums

Supporting Multiple Types Of Administrators


Recommended Posts

                // 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

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

×
×
  • Create New...