I was trying to apply this little code on my codeigniter page to see if the login is going to replace the logout if a user logged in, and vice versa. I tested it on welcome page that comes with codeigniter framework, but nothing happen. The only thin I see is login link. I tried to use tank auth as login library to make things easy, but whenever I login to the welcome page, again the login link shows up again, which is none sense.
here is the code I used to replace login/logout
<?php if(isset($_SESSION['username']) && $_SESSION['username']!="")
{
echo("<a href='logout.php'>Logout</a> ");
echo($_SESSION['username']);
``// displays username
}
else
{
echo("<a href='login.php'>Login</a> ");
}
?>
Perhaps your login script is not setting the $_SESSION properly. Use Firebug to see if you have an active session. I’d also use a method to check whether users are logged in:
Your login class:
Your view: