Edmhar Posted November 1, 2013 Share Posted November 1, 2013 i want to post if logged in i want to have echo logout link if not logged in want to echo login Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 1, 2013 Share Posted November 1, 2013 (edited) There is no standard built in feature for this. A simple example would be when a user successfully logs in you set a session variable like this $_SESSION['logged_in'] = true; To work out what link to show you check this session variable's value. If it is set to true then you output the logout link. Otherwise you output the login link. Example if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) { echo '<a href="logout.php">Logout</a>'; // output logout link } else { echo '<a href="login.php">Login</a>'; // output login link } Edited November 1, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Edmhar Posted November 1, 2013 Author Share Posted November 1, 2013 There is no standard built in feature for this. A simple example would be when a user successfully logs in you set a session variable like this $_SESSION['logged_in'] = true; To work out what link to show you check this session variable's value. If it is set to true then you output the logout link. Otherwise you output the login link. Example if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) { echo '<a href="logout.php">Logout</a>'; // output logout link } else { echo '<a href="login.php">Login</a>'; // output login link } thanks man your great hahaha I love you No homo! you helping me to finish my Thesis Quote Link to comment Share on other sites More sharing options...
Edmhar Posted November 1, 2013 Author Share Posted November 1, 2013 thanks man your great hahaha I love you No homo! you helping me to finish my Thesis how about if will put this in html? Quote Link to comment Share on other sites More sharing options...
Edmhar Posted November 1, 2013 Author Share Posted November 1, 2013 There is no standard built in feature for this. A simple example would be when a user successfully logs in you set a session variable like this $_SESSION['logged_in'] = true; To work out what link to show you check this session variable's value. If it is set to true then you output the logout link. Otherwise you output the login link. Example if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) { echo '<a href="logout.php">Logout</a>'; // output logout link } else { echo '<a href="login.php">Login</a>'; // output login link } how about if i put this in html? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 1, 2013 Share Posted November 1, 2013 (edited) Yes you can surround the if/else with HTML code. So long as the file still has a .php extension and you are starting the session before you output the html. Example with html <?php session_start(); //start the session before the html ?> <html> <head> <title>Page title</title> </head> <body> <div id="container"> <div id="header"> <h1>Header</h1> <div id="nav"> <?php // output login or logout links here if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) { echo '<a href="logout.php">Logout</a>'; // output logout link } else { echo '<a href="login.php">Login</a>'; // output login link } ?> </div> </div> <div id="content"> page content </div> </div> </body> </html> Edited November 1, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
Edmhar Posted November 2, 2013 Author Share Posted November 2, 2013 Yes you can surround the if/else with HTML code. So long as the file still has a .php extension and you are starting the session before you output the html. Example with html <?php session_start(); //start the session before the html ?> <html> <head> <title>Page title</title> </head> <body> <div id="container"> <div id="header"> <h1>Header</h1> <div id="nav"> <?php // output login or logout links here if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true) { echo '<a href="logout.php">Logout</a>'; // output logout link } else { echo '<a href="login.php">Login</a>'; // output login link } ?> </div> </div> <div id="content"> page content </div> </div> </body> </html> Thank you i passed this problem hahaha kindly check my new post simple add and subtract mysql and php Quote Link to comment 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.