Jump to content

Hide cart if not logged in


djlfreak

Recommended Posts

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>

 

 

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.