divinedesigns1 Posted June 28, 2012 Share Posted June 28, 2012 (edited) 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 June 28, 2012 by DDs1 Link to comment Share on other sites More sharing options...
birbal Posted June 28, 2012 Share Posted June 28, 2012 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 More sharing options...
birbal Posted June 28, 2012 Share Posted June 28, 2012 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 More sharing options...
divinedesigns1 Posted June 28, 2012 Author Share Posted June 28, 2012 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 itok ill try thatdid you set the session previously? to use session acrosss pages you have to start session using session_start() on top of the each pageand yes i started the session at the very top of the page, with the session_start() Link to comment Share on other sites More sharing options...
birbal Posted June 28, 2012 Share Posted June 28, 2012 (edited) it should be something like... <?phpif(isset($_SESSION['user'])){echo "Welcome, {$_SESSION['user']}!";}else{die("You must be logged in");}?> Edited June 28, 2012 by birbal Link to comment Share on other sites More sharing options...
divinedesigns1 Posted June 28, 2012 Author Share Posted June 28, 2012 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now