session logout button bootstrap
<p>I have made a login form, where I also have sessions. That is working fine, and you can also see that I get more buttons visible, when I am logged in. I would like that my Login in the topright hand corner switch to the name of the user, and in the dropdown menu I get a red button where it says logout. I have been trying to do some of the coding I do with the buttons... Where I <code>&lt;?php include 'buttons.php' ?&gt;</code>. But I cannot get anything to work. </p>

<p>The logout button you see in the left side is working, so the question is more, how can I get it in the dropdown menu instead?</p>

<p><a href="https://i.stack.imgur.com/oTWEk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oTWEk.png" alt="Login"></a>
<a href="https://i.stack.imgur.com/KDalk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KDalk.jpg" alt="Logout"></a></p>

<p>header.php</p>

<pre><code>&lt;nav class="navbar navbar-default navbar-fixed-top topnav" role="navigation"&gt;
        &lt;div class="container topnav"&gt;
            &lt;!-- Brand and toggle get grouped for better mobile display --&gt;
            &lt;div class="navbar-header"&gt;
                &lt;button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"&gt;
                    &lt;span class="sr-only"&gt;Toggle navigation&lt;/span&gt;
                    &lt;span class="icon-bar"&gt;&lt;/span&gt;
                    &lt;span class="icon-bar"&gt;&lt;/span&gt;
                    &lt;span class="icon-bar"&gt;&lt;/span&gt;
                &lt;/button&gt;
                &lt;a class="navbar-brand topnav" href="index.php"&gt;Logo&lt;/a&gt;
            &lt;/div&gt;
            &lt;!-- Collect the nav links, forms, and other content for toggling --&gt;
            &lt;div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"&gt;
                &lt;ul class="nav navbar-nav navbar-right"&gt;
                    &lt;li&gt;
                        &lt;a href="#about"&gt;About&lt;/a&gt;
                    &lt;/li&gt;
                    &lt;li&gt;
                        &lt;a href="#services"&gt;Services&lt;/a&gt;
                    &lt;/li&gt;
                    &lt;li&gt;
                        &lt;a href="#contact"&gt;Contact&lt;/a&gt;
                    &lt;/li&gt;
                    &lt;?php include 'buttons.php' ?&gt;

            &lt;!-- Login Form --&gt;
     &lt;ul class="nav navbar-nav navbar-right"&gt;
        &lt;li class="dropdown"&gt;
          &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;&lt;b&gt;Login&lt;/b&gt; &lt;span class="caret"&gt;&lt;/span&gt;&lt;/a&gt;
            &lt;ul id="login-dp" class="dropdown-menu"&gt;
                &lt;li&gt;
                     &lt;div class="row"&gt;
                            &lt;div class="col-md-12"&gt;
                                Login via
                                &lt;div class="social-buttons"&gt;
                                    &lt;a href="#" class="btn btn-fb"&gt;&lt;i class="fa fa-facebook"&gt;&lt;/i&gt; Facebook&lt;/a&gt;
                                    &lt;a href="#" class="btn btn-tw"&gt;&lt;i class="fa fa-twitter"&gt;&lt;/i&gt; Twitter&lt;/a&gt;
                                &lt;/div&gt;
                                or
                                 &lt;form class="form" role="form" method="post" action="" accept-charset="UTF-8" id="login-nav"&gt;
                                        &lt;div class="form-group"&gt;
                                             &lt;label class="sr-only" for="exampleInputEmail2"&gt;Email address&lt;/label&gt;
                                             &lt;input type="email" name="username" class="form-control" id="exampleInputEmail2" placeholder="Email address" required&gt;
                                        &lt;/div&gt;
                                        &lt;div class="form-group"&gt;
                                             &lt;label class="sr-only" for="exampleInputPassword2"&gt;Password&lt;/label&gt;
                                             &lt;input type="password" name="password" class="form-control" id="exampleInputPassword2" placeholder="Password" required&gt;
                                             &lt;div class="help-block text-right"&gt;&lt;a href=""&gt;Forget the password ?&lt;/a&gt;&lt;/div&gt;
                                        &lt;/div&gt;
                                        &lt;div class="form-group"&gt;
                                             &lt;button type="submit" name="submit" class="btn btn-primary btn-block"&gt;Sign in&lt;/button&gt;
                                        &lt;/div&gt;
                                        &lt;div class="checkbox"&gt;
                                             &lt;label&gt;
                                             &lt;input type="checkbox"&gt; keep me logged-in
                                             &lt;/label&gt;
                                        &lt;/div&gt;
                                 &lt;/form&gt;
                            &lt;/div&gt;
                            &lt;div class="bottom text-center"&gt;
                                New here ? &lt;a href="join.php"&gt;&lt;b&gt;Join Us&lt;/b&gt;&lt;/a&gt;
                            &lt;/div&gt;
                     &lt;/div&gt;
                &lt;/li&gt;
            &lt;/ul&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
           &lt;!-- /.Login Form --&gt;
        &lt;/div&gt;
        &lt;!-- /.container --&gt;
    &lt;/nav&gt;
</code></pre>

<p>profile.php</p>

<pre><code>&lt;body&gt;
    &lt;?php require 'header.php' ?&gt;
&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;
    &lt;div id="container"&gt;
        &lt;div class="topbar"&gt;
            &lt;h4 class="hello"&gt;Hello, &lt;em&gt;&lt;?php echo $_SESSION['username'];?&gt;!&lt;/em&gt;
            &lt;a href="logout.php" style="font-size:18px"&gt;Logout?&lt;/a&gt;
        &lt;a href="test.php"&gt;test&lt;/a&gt;&lt;/h4&gt;
        &lt;/div&gt;

    &lt;/div&gt;
&lt;/body&gt;
</code></pre>

<p>session.php:</p>

<pre><code>&lt;?php
    if( !isset( $_SESSION ) ) session_start();
    if( !isset( $_SESSION['username'] ) ) exit( header('Location: index.php') );
?&gt;
</code></pre>