Thursday, 8 August 2013

Check if session exists

Check if session exists

I have a script that handles a user logging in and then directs him to the
index page where he has an option to log out. Here is the index page code
at the moment:
<?php
session_start();
?>
<html>
<body>
<?php
echo 'You are logged in as : ';
echo $_SESSION['username'];
echo '<p><a href="logout.php">Logout</a></p>';
?>
</body>
</html>
If the user logs out it still shows the text. How can I check if the
session still actually exists and display a different message accordingly?
IE: Display "You are not connected" and the login link if the user is not
logged in?

No comments:

Post a Comment