benji87 Posted March 21, 2006 Share Posted March 21, 2006 Hey all. Im currently working on a user section for my new site and im trying to define a user image using sessions but im having a little problem and dont know what to do next.Here is my code so far:[b]checkuser.php (registering variable):[/b]session_register('loggedin');$_SESSION['loggedin'] = 0;[b]login_success.php:[/b]<? if(loggedin == 0){echo '<img src=/userimgs/ben.gif>';}else {echo '<img src=/userimgs/standard.gif>';}?>With the if statement i want to draw the users image url from the database if they are logged in but im not sure how to go about that i did try:$query("SELECT userimg FROM mydatabase WHERE username='username'")$result=mysql_query($query);But i had no luck with that.So i used the image source above just to test to see if the image would not appear if i was not logged in. But it appears even if im not logged in! I hope someone can guide me in the right direction coz i think im heading that way, i hope! Quote Link to comment https://forums.phpfreaks.com/topic/5453-session-images/ Share on other sites More sharing options...
kenrbnsn Posted March 22, 2006 Share Posted March 22, 2006 Your programming style assumes that register_globals is enabled. This could be a false assumption, since the default has been "disabled" for at least 3 years. Do not use register_session(). Instead use the session variable directly.Your code would then look like (checkuser.php (registering variable)):[code]<?phpsession_start(); // always should be the first executable line in each script where you use sessions$_SESSION['loggedin'] = 0;?>[/code]login_success.php:[code]<?phpsession_start();if($_SESSION['loggedin'] == 0) echo '<img src=/userimgs/ben.gif>';else echo '<img src=/userimgs/standard.gif>';?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/5453-session-images/#findComment-19687 Share on other sites More sharing options...
benji87 Posted March 23, 2006 Author Share Posted March 23, 2006 Thanks that code worked great! But there is still one problem! Ive used the same method for the text that appears next to the image that welcomes the user but if you go onto my site and you are not logged in then the code wont skip to the else statement because im guessing it cant find the session variable. So how am i meant to get it to display the else statement without registering the varibles first? As my varibles are registered in the login process... Here is my code below:user image code:[code]<?phpsession_start();if($_SESSION['loggedin'] == 0) echo $_SESSION['userimg'];else echo '<img src=/userimgs/user.gif>';?>[/code]user text code:[code]<?phpsession_start();if($_SESSION['loggedin'] == 0) echo "Welcome ". $_SESSION['username'] ."<br>You are logged in.<br />";else echo "Please login or register";?>[/code]heres my website: [a href=\"http://www.bubblebox-design.co.uk\" target=\"_blank\"]Studio2310[/a] Quote Link to comment https://forums.phpfreaks.com/topic/5453-session-images/#findComment-20127 Share on other sites More sharing options...
benji87 Posted March 27, 2006 Author Share Posted March 27, 2006 bump Quote Link to comment https://forums.phpfreaks.com/topic/5453-session-images/#findComment-21277 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.