How can PHP be used to redirect users to different pages based on their login credentials?
To redirect users to different pages based on their login credentials in PHP, you can first check the user's credentials against a database or other authentication method. Once verified, you can use the header() function to redirect the user to the appropriate page based on their role or permissions.
// Check user credentials
if($authenticated) {
if($user_role == 'admin') {
header("Location: admin_page.php");
exit();
} elseif($user_role == 'user') {
header("Location: user_page.php");
exit();
} else {
header("Location: default_page.php");
exit();
}
} else {
header("Location: login_page.php");
exit();
}