I have this really annoying problem with showing up a username if the user is logged from the previous PHP file.
In a navbar, I want to show his username if he's registered or show this "Přihlásit se" link ("log in" in Czech).
So, I created the source.txt file, which is like a base code for the environment of the website (I always want that navbar, where a user can see if he's logged or not and some other stuff)
First file source.txt
<div class="container">
<ul class="nav-main">
<?php
if (isset($user_id)) {
echo ("<li><a>$user_name</a></li>");
}
else {
echo ("<li><a>Přihlásit se</a></li>");
}
?>
Second file index.php
<?php
if (isset($_POST['user_id'])) {
$user_id = $_POST['user_id'];
$user_name = $_POST['user_name'];
}
readfile ("html/source.txt");
?>
I expect the output "Přihlásit se" link, because I haven't set the $user_id with POST method.
But actual output is just this:
$user_name"); } else { echo ("
Přihlásit se
"); } ?>