Q: Logged in user name and last name wont show on the navbar I'm a beginner in php and I want the name and last name of the logged in user to show on my navbar. Instead it shows the php code. This is my code inside the navbar. 
<?php 
    echo "<p>" . $_SESSION['vorname'] . " " . $_SESSION['nachname'] . "</p>";
?>

This is what it shows instead. 
The output on the screen.
I changed the file extension to .php and this is what it outputs now.

A: PHP-Files have to be saved with the .php file extension to be executed. I suppose the other working files all have the right file extension?

A: You have to save all files with php code as .php.
Inside them you can use clean HTML:
<html>
<head></head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

or HTML mixed with PHP:
<html>
<head></head>
<body>
    <?php echo '<h1>Hello, World!</h1>'; ?>
    <?php echo '<p>You are logged as '.$_SESSION['vorname'].' '.$_SESSION['nachname'].'</p>'; ?>
</body>
</html>

And remember to use PHP server (XAMPP, WAMP) on localhost - PHP files will not work if you open them directly in web browser (i.e. file:///C:/xampp/htdocs/hello/index.php )

A: The notice suggests that session is not started in your script, so you need to call session_start() prior to accessing $_SESSION variable. It would also be wise to check whether the user is logged in or not:
<?php
    session_start();
    if (isset($_SESSION['vorname'], $_SESSION['nachname'])) {
      echo "<p>" . $_SESSION['vorname'] . " " . $_SESSION['nachname'] . "</p>";
    } else {
      echo "<p>No user is logged in</p>";
    }
?>

