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
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).
Link to comment
Share on other sites

I know how to echo a session, and how to use parenthesis. Im doing that so I see if the session is set and updates itself.

I do start the class though.

// Start sessions
session_start();
header("Cache-control: private");
$_SESSION["cart"] = new Cart;
Link to comment
Share on other sites

[!--quoteo(post=385509:date=Jun 18 2006, 08:42 PM:name=tiki)--][div class=\'quotetop\']QUOTE(tiki @ Jun 18 2006, 08:42 PM) [snapback]385509[/snapback][/div][div class=\'quotemain\'][!--quotec--]$_SESSION["cart"] = new Cart;
[/quote]
What is line 9 then?
Link to comment
Share on other sites

[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]
Link to comment
Share on other sites

[!--quoteo(post=385537:date=Jun 19 2006, 05:48 AM:name=tiki)--][div class=\'quotetop\']QUOTE(tiki @ Jun 19 2006, 05:48 AM) [snapback]385537[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Wtf are u talking about?
[/quote]
post whole page
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.