Skip to content
PHP Logo

How can one dynamically change the interface displayed to a user based on their login status in PHP without creating a new page?

To dynamically change the interface displayed to a user based on their login status in PHP without creating a new page, you can use PHP to conditionally display different content based on whether the user is logged in or not. This can be achieved by checking the user's login status and then using if-else statements to show different HTML elements or content accordingly.

php
<?php
session_start();

// Check if user is logged in
if(isset($_SESSION['user_id'])) {
    // Display content for logged in users
    echo "Welcome, ".$_SESSION['username']."!";
    echo "<a href='logout.php'>Logout</a>";
} else {
    // Display content for non-logged in users
    echo "<a href='login.php'>Login</a>";
    echo "<a href='register.php'>Register</a>";
}
?>