How to validate a php session?

Nik

New member
I have a code that displays the users name if they are logged in but when they are not logged in I get an error message obviously because it can't echo nothing it errors but as mentioned when they log in it is fine. So how do i code an if statment so that it checks to see if the session returns true if so display the username if false display welcome. Here is the code I have so far
<?php session_start(); ?>

<?php
if ($_SESSION['username'] == false ) {
echo "Welcome to learning computers uk";
}
else
{
echo "Welcome"; echo " "; echo $_SESSION['username'];
}
?>

The code above still displays an error but still works if they are logged in so the if statment is practically useless (the one above.)
Thanks for any help.
 
Back
Top