I'm trying to create a session once a user logs in so that the 'log in' menu item changes to 'log out' for the duration they are logged in. Once logged in, my success.php file runs which is just
<?php
session_start();
$_SESSION['loggedin'] = 1;
?>
Now under the menu I have
<?php
if($_SESSION['loggedin']=1)
echo '<a href="logout.php">Logout</a>';
else
echo '<a href="login.html">Login</a>';
?>
I also have a logout page which is just
<?php
session_start();
session_destroy();
?>
What's happening here though is that by default, the logout option is showing rather than log in even though the user hasn't yet logged in to create the session.
I'm not sure if this is the correct way of handling this, but some advice is very much appreciated.
Thanks.