0

I have a login bar and after login i want to transform login in username. login bar

index.php login form is looking like that:

<form action="login.php" method="post">
       <input class="input_form_login_top" type="text" id="login_username" placeholder="username" name="login_username"required>
       <input class="input_form_login_top" type="password" id="login_password" placeholder="password" name="login_password" required>
        <button type="submit" name="submit" class = "button_login_top"> Login </button>


    <button onclick="document.getElementById('id01').style.display='block'" style="width:auto;" class="button_signup_top"> Sign Up</button>
</form>
StringDotZ
  • 11
  • 4
  • 1
    Welcome to [so]! At this site you are expected to try to **write the code yourself**. After **[doing more research](//meta.stackoverflow.com/questions/261592)** if you have a problem you can **post what you've tried** with a **clear explanation of what isn't working** and providing a [**Minimal, Complete, and Verifiable example**](//stackoverflow.com/help/mcve). I suggest reading [ask] a good question and [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/). Also, be sure to take the [tour] and read **[this](//meta.stackoverflow.com/questions/347937/)**. – John Conde May 31 '17 at 14:11
  • You May Try it With `$_SESSION`. – Adharsh M May 31 '17 at 14:15
  • I have session..i login..but i don t know what to do after that – StringDotZ May 31 '17 at 14:26
  • @StringDotZ you wanna change the login button to the username after login? – Masivuye Cokile May 31 '17 at 14:28

1 Answers1

0

This is what you need in the login bar have an if statement that will check if the user have logged in or not using the session you that you where setting on login page, then if the user is loggedin show what ever html content you wanna show on that login bar or else show the login form

<?php
session_start();
    if(isset($_SESSION['whatEverYouCallIT']) && !empty($_SESSION['whatEverYouCallIT'])):?>

            <!-- The user have logged display what ever html content you want here in the login bar  -->
        <a class="button_login_top" href="profile.php?user=<?=$_SESSION['whatEverYouCallIT']?>">Hell <? = $_SESSION['whatEverYouCallIT']?></a>
        <a class="button_login_top" href="logout">Log out</a>
    <?php

        else : ?>

        <!-- Display the html login form -->
        <form action="login.php" method="post">
       <input class="input_form_login_top" type="text" id="login_username" placeholder="username" name="login_username"required>
       <input class="input_form_login_top" type="password" id="login_password" placeholder="password" name="login_password" required>
        <button type="submit" name="submit" class = "button_login_top"> Login </button>


    <button onclick="document.getElementById('id01').style.display='block'" style="width:auto;" class="button_signup_top"> Sign Up</button>
</form>
<?php

    endif;
?>
Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34