Jump to content

sessions ending abruptly why?!?!?!


tiki

Recommended Posts

I have a cart system that uses sessions to track all the items in the cart, and price etc. The cart system uses a global cart class to do all its functions, but whenever you add an item to the cart, it works correctly then the sessions get messed up, why?

Test it out here, and add the item, then browse around and it messes up!

[a href=\"http://www.mileswjohnson.com/clients/Cssbooth/browse/MJ0001GR/1/\" target=\"_blank\"]http://www.mileswjohnson.com/clients/Cssbo...wse/MJ0001GR/1/[/a]

The sessions are echoed at the top as so:

echo $_SESSION;
print_r $_SESSION;
print_r $_SESSION["cart"];

I get these errors mostly:
Fatal error: Call to a member function on a non-object in /home/mileswjo/public_html/clients/Cssbooth/viewcart.php on line 9
Link to comment
https://forums.phpfreaks.com/topic/12342-sessions-ending-abruptly-why/
Share on other sites

To begin with, why are you echoing $_SESSION? You can't use echo with arrays - actually you can but it's not pretty.

Then, you don't need to print_r $_SESSION['cart'] if you already printed $_SESSION. And you must use parenthesis when calling functions:

print_r($_SESSION);

And anyway, your error shouldn't be caused by this, but as result of uninitialized class. (calling $class->method() for example).
[a href=\"http://www.mileswjohnson.com/clients/Cssbooth/cart/\" target=\"_blank\"]http://www.mileswjohnson.com/clients/Cssbooth/cart/[/a]

This is the error lines, starting at 32.
[code]
$empty = $_SESSION["cart"]->items(); ?>

<div class="half">
<? if ($empty == 0) { ?>

    <p class="title">Your cart is empty</p>
    <p><a href="browse/">Browse</a> our templates and add them to your cart!</p>
    
<? return false; } ?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.