Jump to content

Persistant objects...


KevinM1

Recommended Posts

I'm not sure if this should be here or in the 'application design' section, so please move it to the right spot.

I'm currently trying to save my shopping cart object so that when a customer moves from one page to another, their cart's information remains available.  Normally, I'd just save their cart in a database, save it when a page exits, and retrieve it when another page loads, but we're not using a database to store any client info (definitely not my design choice).  So, I basically have to pass the shopping cart from page to page (using sessions) without any database interaction whatsoever.  I'm not 100% sure how to do it, though.  I'm thinking of something along the lines of:
[code]
<?php

include('../php_config/config.php'); //this autoloads my classes

session_start();

if(!isset($_SESSION['cartInfo'])){
  $myCart = new ShoppingCart();
}

else{
  $myCart = urldecode(unserialize($_SESSION['cartInfo']));
}
.
.
.
?>
[/code]

My biggest concern is how to save the shopping cart before the user goes to a different page.  I'm not sure when to serialize and encode the object in my scripts.  I'm also wondering if I should make my shopping cart object a singleton, as logically there is only one cart available to the user.

Any ideas?
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.