TheJoey Posted October 10, 2009 Share Posted October 10, 2009 Hey im trying to make a bit of script that will hide links from users that arent logged in. <?php if(!$_SESSION["loginsuccessfull"]) { echo '<h2><a href="order.php">Proceed to Order Page</a></h2> <h2><a href="products.php">Continue Shopping</a></h2> <h2><a href="resetcart.php">New Cart</a></h2> <h2><a href="ordertest.php">Proceed to Order Page session</a></h2>'; } else { echo ' <h2><a href="login.php">Login to view Order Page</a></h2> <h2><a href="products.php">Continue Shopping</a></h2> <h2><a href="resetcart.php">New Cart</a></h2> '; } ?> but even if i have logged in it still only displays Login to view Order Page Continue Shopping New Cart Link to comment https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/ Share on other sites More sharing options...
thebadbad Posted October 10, 2009 Share Posted October 10, 2009 Are you using session_start()? Link to comment https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/#findComment-934226 Share on other sites More sharing options...
TheJoey Posted October 10, 2009 Author Share Posted October 10, 2009 yup its in my html code, because im including the php code. Link to comment https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/#findComment-934227 Share on other sites More sharing options...
TheJoey Posted October 10, 2009 Author Share Posted October 10, 2009 <?php session_start(); ?> at the top of all my pages Link to comment https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/#findComment-934243 Share on other sites More sharing options...
cags Posted October 10, 2009 Share Posted October 10, 2009 Looking at your code you have... if(!$_SESSION["loginsuccessfull"]) { Assumably loginsuccessfull is a value that you set when the user has successfully logged in. As you have the exclamation mark, it is a check for a user that isn't logged in. That being the case then the items displayed to logged in users will be the ones in the else block. So why does the word login appear in the else block? Also, a quick tip. If you place... echo '<pre>'; print_r($_SESSION); echo '</pre>'; ... at the top of your page, you'll be able to see what session variables you are working with. Link to comment https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/#findComment-934247 Share on other sites More sharing options...
TheJoey Posted October 10, 2009 Author Share Posted October 10, 2009 [loginsuccessfull] => 1 that showed up with the code snippet you gave me. So i shouldnt use ! in my statement? Link to comment https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/#findComment-934250 Share on other sites More sharing options...
TheJoey Posted October 10, 2009 Author Share Posted October 10, 2009 Never knew that ! was used to check if isnt. Thanks again cags your always very helpfull Link to comment https://forums.phpfreaks.com/topic/177184-solved-help-hiding-links/#findComment-934251 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.