473,396 Members | 2,029 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sessions and Objects

Hi,

I'm currently building an object-oriented shopping cart with PHP 4.3.2 and
MySQL 4.0.14.

I am looking at storing a Cart object within a PHP session, however I am not
completely sure on the best way to achieve this. I have read up and there
seems to be varying advice. Should I need to serialise and unserialise the
object or is this automatic and should I be using session_register()? For
reference, register_globals is off.

I'd be grateful if anybody could help.

Thanks in advance,
Matt
Jul 16 '05 #1
3 4006
"Matthew Bates" <ma********@hotmail.com> wrote in message
news:bz*********************@news-text.cableinet.net...
Hi,

I'm currently building an object-oriented shopping cart with PHP 4.3.2 and MySQL 4.0.14.

I am looking at storing a Cart object within a PHP session, however I am not completely sure on the best way to achieve this. I have read up and there seems to be varying advice. Should I need to serialise and unserialise the object or is this automatic and should I be using session_register()? For reference, register_globals is off.

I'd be grateful if anybody could help.


With your version of PHP, you wouldn't want to use session_register()
since it's deprecated.

This also means, your objects are not (un)serialised automatically. So
you'd want to do something like:

At the start of the page:
- include the class (since serialized objects do not contain the class
functions)
- start the session (this must be after the class include)
- unserialize the object

At the end of the page:
- serialize the object

For more info http://php.net/manual/en/language.oop.serialization.php

Jul 16 '05 #2
On Tue, 2 Sep 2003 02:04:43 +0800, "powerboy"
<po******@rarextreme.com> wrote:
"Matthew Bates" <ma********@hotmail.com> wrote:
I'm currently building an object-oriented shopping cart with PHP4.3.2 and
MySQL 4.0.14. Should I need to serialise and unserialise the
object or is this automatic and should I be using
session_register()? For
reference, register_globals is off.

This also means, your objects are not (un)serialised automatically. At the start of the page:
- include the class (since serialized objects do not contain the class
functions)
- start the session (this must be after the class include)
- unserialize the object

At the end of the page:
- serialize the object

For more info http://php.net/manual/en/language.oop.serialization.php


my experience agrees with what the first comment on that page is:
objects are automatically (un)serialized when putting in and getting
out of a session.

if you have resources in your object (like a database connection), you
may want to look at __sleep and __wakeup to shut down and restore them
properly.
Jul 16 '05 #3
Matthew Bates schrieb:
Hi,

I'm currently building an object-oriented shopping cart with PHP 4.3.2 and
MySQL 4.0.14.

I am looking at storing a Cart object within a PHP session, however I am not
completely sure on the best way to achieve this. I have read up and there
seems to be varying advice. Should I need to serialise and unserialise the
object or is this automatic and should I be using session_register()? For
reference, register_globals is off.

I'd be grateful if anybody could help.

Thanks in advance,
Matt


With your PHP version, storing objects in the session should work quite
easy - just set
$_SESSION["cart"] = $your_card_object;

i.e., no serizalize/unserialize is necessary.

One problem may occure when you will retrive the object from the session
- you need to include the class definition before the session starts!

But I found it easier to store only object IDs in the session and to
store/retrieve the object itself from the database.

Regards!
Rainer

--
------------------------------------------------
Rainer Herbst Linux - Registered
ZEIK User #319157
Universität Potsdam Usual disclaimers applies!
------------------------------------------------

Jul 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Yoyoma_2 | last post by:
Hello, i'me having a wierd problems with sessions. PHP 4.3.3, Register globals is on, and the sessions module is installed. if i have a page like this: <? session_start(); $_SESSION="blue";...
3
by: Gary W | last post by:
Hello, I have used SESSIONS on mission critical pages on my site, and if sessions are not enabled / supoorted - these pages will fail. When and why would a session fail? They do not store any...
3
by: Maxime Ducharme | last post by:
Hi group We have a problem with sessions in one of our sites. Sessions are used to store login info & some other infos (no objects are stored in sessions). We are using Windows 2000 Server...
1
by: jty202 | last post by:
1. Can I have an array of objects as sessions variable in other words sessions array-of-objects? If so how? 2. Besides Sessions variable what else can I use to store large amount of data...
3
by: Miguel | last post by:
Hi all friends: It's said that Sessions objects in ASP 3.0 with IIS 5.0 occupy certain memory of the machine which take to take care about use a lot of Sessions objects in the ASPs pages of the...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory†exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
1
by: Sebastian Araya | last post by:
Hello, I'm facing a little problem with php 5.1 and SOAP sessions. I've built a class which uses a few internal objects to solve a query, named CWebService, and I've issued a: $objServer...
3
by: Atul | last post by:
Hi, I am running .NET Framework 2.0 on windows XP SP2. I am stuck in a situation where I need to find out a list of all active sessions running in IIS for a web application. I know that .NET...
3
by: AlonR | last post by:
Hi, We're experiencing random user sessions losses on our web applications, and are researching for any useful information which may shed light on this problem. Environment: In our...
13
Frinavale
by: Frinavale | last post by:
One of the most fundamental topics in web design is understanding how to pass information collected on one web page to another web page. There are many different ways you could do this: Cookies,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.