BarneyJoe Posted August 15, 2007 Share Posted August 15, 2007 This is hopefully an easy one - just trying to have a link that's to log in if no-one is logged in, and log out if they are. From a bit of a search, I realise it should be : <?php if(isset($_SESSION['username'])) { echo "Logout"; } else { echo "Login"; } ?> Can anyone help me out with the syntax / code to define "Logout" and "Login" Cheers Link to comment https://forums.phpfreaks.com/topic/65057-dynamic-log-in-log-out-links/ Share on other sites More sharing options...
MadTechie Posted August 15, 2007 Share Posted August 15, 2007 whats the problem ? can you have a page with a if(isset($_GET['logout'])) { unset($_SESSION['username']); } Link to comment https://forums.phpfreaks.com/topic/65057-dynamic-log-in-log-out-links/#findComment-324665 Share on other sites More sharing options...
BarneyJoe Posted August 15, 2007 Author Share Posted August 15, 2007 I now have some code : <div id="navcontainer" align="center"> <ul id="navlist"> <li><a href="index.php">Home</a></li> .. <li><?php if(isset($_SESSION['username'])) { echo "Logout"; } else { echo "Login"; } ?> </li> </ul> </div> But presumably I need to define "Logout" and "Login" somewhere? Where do I put the actual links? I've been trying with this sort of thing, but with no joy : <?php $login="<a href="login.php">Login</a>"; $logout="<a href="logout.php">Logout</a>"; ?> Link to comment https://forums.phpfreaks.com/topic/65057-dynamic-log-in-log-out-links/#findComment-324684 Share on other sites More sharing options...
BarneyJoe Posted August 15, 2007 Author Share Posted August 15, 2007 I don't know where I'm going wrong with this - if I have : <?php if(($_SESSION["MM_username"])) { echo '<a href="logout.php>">Log Out</a>'; } else { echo '<a href="login.php">Log In</a>'; } ?> Shouldn't that be it? The session variable seems OK, as it outputs OK with a <?php echo $_SESSION['MM_Username'] ?> I'm getting the Log In link OK, but it's not switching to Log Out when I log in. Link to comment https://forums.phpfreaks.com/topic/65057-dynamic-log-in-log-out-links/#findComment-324769 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.