Just a fore note: I am messing around with HTML / CSS / PHP and MySQL. I do NOT have security in mind just yet.
I have 2 files, the first called page1.php and the second one called page2.php. Pretty simple, they both have a navbar which has some PHP code in it:
if (isset($_SESSION["loggedin"])){
echo "<li class='navbar-button' id='right-status'><a>Logged in as admin</a></li>
";
echo "<li class='navbar-button' id='right-change'><a href='logout.php'>Log Out</a></li>
";
} else {
echo "<li class='navbar-button' id='right-change'><a href='login.html'>Log In</a></li>";
}
It checks whether or not a current session data named 'loggedin' exists, if it does it shows "Logged in as admin - Log Out" on the navbar. If it cannot find this session data, it shows "Log In" on the navbar. When I load page1.php, on the navbar it shows "Logged in as admin - Log Out", however when I load page2.php it shows "Log In". These both have identical code, and i m not sure why they produce different results. I'm not sure if it's relevant, but page2.php is not stored in the same folder as page1.php. Page1.php's directory is /page1.php. Page2.php's directory is /folder/page2.php.
Question 1: Do PHP sessions store data globally over every single file / folder in the entirety of the website? Or just in the root folder?
Question 2: Why does my code give different answers?
Thank you for your time in advance.
:)
Edit:
Sorry forgot to mention, page2.php was computer-generated using PHP.