edgarasm Posted November 11, 2013 Share Posted November 11, 2013 Hi there I am looking on how to hide buttons once the session has been initiated so the user doesnt see the buttons if he is logged in until he logs out I have a div with both buttons not sure whereever i would need to hide the div <div class="one_sixth" style="padding-top: 0px;"> <td><a href="../account/loginprocess.php"<input type="submit" id="login_submit" name="login_submit" style="background: light_blue;" class="button" value="Login to Account">Login</a></td> <td><a href="/account/register.php" id="login_submit" name="login_submit" input type="submit" style="background: light_blue;" class="button" value="Register">Sign Up</a></td> </div> Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/ Share on other sites More sharing options...
Solution Ch0cu3r Posted November 11, 2013 Solution Share Posted November 11, 2013 (edited) When the user is loggged in set a session varibal such as $_SESSION['logged_in'] = true; You can use a simple if statement to display the logout link if they are logged in. Otherwise display the login link if(isset($_SESSION['logged_in') && $_SESSION['logged_in'] == true) { // display logout link } else { // display login link } Also the HTML code you have posted for the login and register links/buttons is invalid html. You appear to of merged a link and a button together. Edited November 11, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/#findComment-1457905 Share on other sites More sharing options...
edgarasm Posted November 11, 2013 Author Share Posted November 11, 2013 Hi i dont really get how to use that :/where would i have to include that? also i couldnt get my buttons to work otherwise thanks Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/#findComment-1457912 Share on other sites More sharing options...
Ch0cu3r Posted November 11, 2013 Share Posted November 11, 2013 also i couldnt get my buttons to work otherwise That is because your HTML for those buttons is invalid. You have merged the anchor (<a> ) tag and button (<input>) tag together you cannot do that. You are better of using anchors tags and then use CSS to style them to look like buttons. Hi i dont really get how to use that :/where would i have to include that? You place that code where you want the login/logout buttons to be displayed. Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/#findComment-1457915 Share on other sites More sharing options...
edgarasm Posted November 11, 2013 Author Share Posted November 11, 2013 i dont have a logout button it only apears as <li> when user logged in, near my account <li> Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/#findComment-1457921 Share on other sites More sharing options...
edgarasm Posted November 11, 2013 Author Share Posted November 11, 2013 Maybe you could see on my teamviewer what im on about in more details Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/#findComment-1457922 Share on other sites More sharing options...
Ch0cu3r Posted November 11, 2013 Share Posted November 11, 2013 i dont have a logout button it only apears as <li> when user logged in, near my account <li> Then use if(!isset($_SESSION['logged_in') || (isset($_SESSION['logged_in') && $_SESSION['logged_in'] != true)) { // display login link } Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/#findComment-1457926 Share on other sites More sharing options...
KaiSheng Posted November 12, 2013 Share Posted November 12, 2013 (edited) Use this and edit yourself. ---- <?php if (isset($_SESSION['user_id'])) { if ($_SESSION['role'] == 'ban') { echo '<meta http-equiv="refresh" content="0; url=ban.php " />'; die(); } elseif ($_SESSION['role'] == 'member'){ ?> <nav> <a href="home.php">Home | </a> <a href ="accountPanel.php">Account Panel | </a> <a href="logout.php">Logout</a><br /> </nav> </header> <?php $link = mysqli_connect($HOST, $USERNAME, $PASSWORD, $DB); //match the username and password entered with database record $query = ("SELECT id,role,username FROM `users` WHERE id='".$_SESSION['user_id']."'"); $result = mysqli_query($link, $query) or die(mysqli_error($link)); $row = mysqli_fetch_array($result); $_SESSION['user_id']= $row['id']; $_SESSION['username'] = $row['username']; $_SESSION['role'] = $row['role']; echo '<p><i>Welcome, '. $_SESSION['username'];?> <br> <?php echo 'You are logged in as ' . '(' . $_SESSION['role'] . ')' ?> <br> <?php } else{ ?> <nav> <a href="home.php">Home | </a> <a href ="adminPanel.php">Admin Panel | </a> <a href="logout.php">Logout</a><br /> </nav> </header> <?php }} else { ?> <nav> <a href="home.php">Home</a> <a href ="register.php">Register</a> <a href="login.php">Login</a><br /> </nav> </header> <?php } ?> -- note, the last part ^ is the condition for user it is not login. Edited November 12, 2013 by KaiSheng Quote Link to comment https://forums.phpfreaks.com/topic/283816-how-to-hide-buttons-after-user-logged-in/#findComment-1457985 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.