Jump to content

Recommended Posts

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

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>";
?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.