How can a user be greeted on a website after successfully logging into a PHP forum?

After a user successfully logs into a PHP forum, you can greet them by displaying a personalized message on the website. This can be achieved by storing the user's name in a session variable during the login process and then retrieving it to display a greeting message on the forum's homepage.

session_start();

// Check if the user is logged in and retrieve their username
if(isset($_SESSION['username'])) {
    $username = $_SESSION['username'];
    echo "Welcome back, $username!";
} else {
    echo "Welcome to the forum!";
}