How can the PHP code be improved to ensure that users with "Admin" rights are directed to the correct section?
The PHP code can be improved by checking the user's role when they log in and redirecting users with "Admin" rights to the correct section. This can be done by adding a conditional statement that checks the user's role before redirecting them.
// Check if user is logged in and has "Admin" rights
if(isset($_SESSION['role']) && $_SESSION['role'] == 'Admin') {
header("Location: admin_section.php");
exit();
} else {
header("Location: regular_section.php");
exit();
}
Related Questions
- What are some alternative methods to achieve the same result as using substr() function in PHP to extract data from text strings?
- What are some common mistakes or misunderstandings that beginners may encounter when trying to use PHP for URL redirection?
- How can HTML be formatted to display line breaks from a PHP input in a MySQL database?