使用PHP会话更改更改html菜单项

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.

For login:

if username and password is ok {

session_start();
$_SESSION['loggedin'] = "something";

}

For the menu

  if(isset($_SESSION['loggedin'])) {
    echo "<a href="logout.php"> logout </a>";
    } else {

    echo "<a href="login.php"> login </a>";
    }

Ok, in order for the session to be remembered as you change pages, you should create a file called session.php and store following code.

<?php 

    session_start();

     if(isset($_SESSION['loggedin']) && !empty($_SESSION['loggedin'])) {

     return true;
     }else {
     return false;
     }
     }

 ?>

Now, include this page in every one of your .php pages

if($_SESSION['loggedin']=1)

should be:

if($_SESSION['loggedin']===1)

For menu You can Do like this

if(isset($_SESSION['user_email']))
            {
            print "<span class=\"userg1\"><strong>".$user."</strong></span>&nbsp";
            print "<form method=\"link\" action=\"logout.php\">
            <input type=\"submit\" name=\"Log Out\" value=\"Log Out\" class=\"f1\"/>&nbsp;
            </form>";
            }
            else
            {
            print "<form method=\"link\" action=\"formvu.php\">
            <input type=\"submit\" name=\"log In\" value=\"Register\" class=\"f1\"/>&nbsp;
            </form><form method=\"link\" action=\"login2.php\">
                <input type=\"submit\" name=\"log In\" value=\"Log In\" class=\"f1\"/>&nbsp;
                </form>";
            }

But do check session before loading full page in very start of page