djlfreak Posted May 26, 2010 Share Posted May 26, 2010 I want to hide the shopping cart if the user is not logged in? How do I change this? <div class="col2"><!-- Column 2 start --> <div id="leftnav"> <?php require_once 'include/leftNav.php'; ?> </div> <div id="minicart"> <?php require_once 'include/miniCart.php'; ?> </div> </div> </div> I tried this but it didn't work. <?php if (isset($_SESSION['name'])) { echo '<div id="minicart">'; } else { echo ' '; } ?> <?php if (isset($_SESSION['name'])) { require_once 'include/miniCart.php'; ?> } else { require_once ' '; } ?> </div> </div> Quote Link to comment https://forums.phpfreaks.com/topic/202922-hide-cart-if-not-logged-in/ Share on other sites More sharing options...
jd307 Posted June 10, 2010 Share Posted June 10, 2010 To use sessions, you need to use session_start(); before using $_SESSION. ... session_start(); if(isset($_SESSION['name'])) { echo "<div id='minicart'>"; require_once('include/miniCart.php'); echo "</div>"; } ... If isset($_SESSION['name'])) returns as false and you don't want anything else to happen, you don't need to set an ELSE within your IF statement. Let me know how you get on. Quote Link to comment https://forums.phpfreaks.com/topic/202922-hide-cart-if-not-logged-in/#findComment-1070185 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.