virtuexru Posted November 22, 2006 Share Posted November 22, 2006 I'm trying to create a rule, if a user is logged in, he see's this menu button. If he's not, he doesn't see it. I see it regardless or not if the user is logged in....<? if (isset($_SESSION['image_is_logged_in'])) { echo "<a href='main.php'>My Profile</a>"; } else { echo "<a href='register.php'>Register</a>"; }?>Should I be doing if($_SESSION['image_is_logged_in'] = true) {} else {} ? Quote Link to comment https://forums.phpfreaks.com/topic/28147-whats-wrong-with-this-if-statement-simple-test-wont-work/ Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 assuming that the session has started, that should take...and with theif($_SESSION['image_is_logged_in'] =="true"){ }else{ }that really depends on what that var is usually set to... Quote Link to comment https://forums.phpfreaks.com/topic/28147-whats-wrong-with-this-if-statement-simple-test-wont-work/#findComment-128731 Share on other sites More sharing options...
virtuexru Posted November 22, 2006 Author Share Posted November 22, 2006 // set the session $_SESSION['image_is_logged_in'] = true;And yea I did start the session Quote Link to comment https://forums.phpfreaks.com/topic/28147-whats-wrong-with-this-if-statement-simple-test-wont-work/#findComment-128735 Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 then ya... no harm in trying... Quote Link to comment https://forums.phpfreaks.com/topic/28147-whats-wrong-with-this-if-statement-simple-test-wont-work/#findComment-128740 Share on other sites More sharing options...
virtuexru Posted November 22, 2006 Author Share Posted November 22, 2006 Yea it worked, thank you taith. :) Quote Link to comment https://forums.phpfreaks.com/topic/28147-whats-wrong-with-this-if-statement-simple-test-wont-work/#findComment-128746 Share on other sites More sharing options...
wildteen88 Posted November 22, 2006 Share Posted November 22, 2006 When the user logs out what is the [b]$_SESSION['image_is_logged_in'][/b] variable set to.ALso the following code does not check the value of the variable but the existance of it:[code]if (isset($_SESSION['image_is_logged_in']))[/code]You'll want to add an [b]and[/b] expression (&&) after the isset function to see if the variables value is true, like so:[code=php:0]if (isset($_SESSION['image_is_logged_in']) && $_SESSION['image_is_logged_in'] == TRUE)[/code] Quote Link to comment https://forums.phpfreaks.com/topic/28147-whats-wrong-with-this-if-statement-simple-test-wont-work/#findComment-128749 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.