Jump to content

loging out from a page and cant get username


divinedesigns1
 Share

Recommended Posts

EDIT: Just notice i foorgot to change the topic, anyway the topic suppose to be cant get username, since i fixed the logging out problem ok this is a small problem and im pretty much just over looking it, buttt i was trying to get the person name to be displayed on the main page by doing this

<?phpif($_SESSION['user']){echo "Welcome, " . $_SESSION['user'] = $username . "!";}else{die("You must be logged in");}?>

but instead of getting the username i just get Welcome, !. Which isnt what im trying to do ( ill be looking into this a little more ) just trying to get some pointers from here

Edited by DDs1
Link to comment
Share on other sites

did you set the session previously? to use session acrosss pages you have to start session using session_start() on top of the each page

Link to comment
Share on other sites

and also if you want to check existance of variable isset() should be used. otherwise if you do if($somevar) then $somevar will type casted to boolean when it will be compared.when variable is not set it will be NULL and NULL to boolean type cassting is unpredictable and so have to avoid it

Link to comment
Share on other sites

and also if you want to check existance of variable isset() should be used. otherwise if you do if($somevar) then $somevar will type casted to boolean when it will be compared.when variable is not set it will be NULL and NULL to boolean type cassting is unpredictable and so have to avoid it
ok ill try that
did you set the session previously? to use session acrosss pages you have to start session using session_start() on top of the each page
and yes i started the session at the very top of the page, with the session_start()
Link to comment
Share on other sites

it should be something like...

<?phpif(isset($_SESSION['user'])){echo "Welcome, {$_SESSION['user']}!";}else{die("You must be logged in");}?> 

Edited by birbal
Link to comment
Share on other sites

it should be something like...
<?phpif(isset($_SESSION['user'])){echo "Welcome, {$_SESSION['user']}!";}else{die("You must be logged in");}?> 

thanks but i got it working, sorry i didnt inform you, but ill take down that code tho looks useful
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...