Skip to content
PHP Logo

How can a user be redirected to a protected area after login without needing to refresh the page or click a link?

To redirect a user to a protected area after login without needing to refresh the page or click a link, you can use PHP's header function to send a Location header with the URL of the protected area. This will automatically redirect the user to the desired page without any user interaction.

php
// Check if user is logged in
if($user_logged_in) {
    header("Location: protected_area.php");
    exit();
}