Forum Moderators: coopster

Message Too Old, No Replies

shopping cart

php/xml shopping cart

         

jpl80

4:14 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



What I need is a sort of a shopping cart that is completely PHP/XML. It needs to track a user's items, allow them to add/remove and then print out it's contents. There is no sensitive data in this cart.

My problem is, how do I track all of this data for a user? I have considered the session variable, a global variable, and a flat file. The problems arise when I consider that more than one user may be logged onto the system at the same time. How do I store their unique data in their own place?

coopster

4:46 pm on Sep 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Hi jpl80 and welcome to WebmasterWorld.

A session really is a flat file, or I should say that the default configuration and session handling routines in PHP are setup as flat files. You start a session and PHP automagically assigns a unique filename to the session, storing your $_SESSION variables on the server and the session_name and unique number in a cookie. You see, all the data stays on the server and it matches the user up via that unique session number.

jpl80

11:18 pm on Sep 7, 2005 (gmt 0)

10+ Year Member



Thank you for your response.

So there is no real downside to storing, for example, a large string (300 lines of html) as a variable in a session file? Does the session file have any limits?

coopster

2:49 pm on Sep 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I can't understand why you might want to ...? But I guess it is up to you. Typcially you will see only the data variables stored in a session and the markup that display the data are written out in scripting routines.

I believe the only limitations imposed on the files are those of the underlying operating system. PHP Sessions [php.net] in the manual pages is a must-read if you are going to be working with sessions at all.

jpl80

3:14 pm on Sep 8, 2005 (gmt 0)

10+ Year Member



The reason I want to do this has more to do with the requirements given to me by my client than personal preference. My client can't afford a database, so I have to have some way to track their items. Only their items aren't variables that refer to some product, but strings of html (html because of formatting) that have to be displayed later. You see? Is there a better way that I could do this?

Thanks,

coopster

3:27 pm on Sep 8, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



A database.

hehe, just kidding you. I understand. Well, you can certainly store strings in your session files, but the bigger question at this point is do you really want to? I'm not sure how I would approach this any differently ... except maybe to keep each string in a file by itself and refer to that string in a "products" script. Maybe build a script or function that contains all the "html file string" filenames and use that to populate your session *cart* information. Then when it comes time to display it, read in that html file string.

Either or, it is going to work. Kind of messy though, I don't envy you.

ergophobe

3:34 pm on Sep 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




can't afford a database

Are you serious? MySQL and PostgreSQL are *free* and are installed on most of the cheapest hosts around. I'm surprised, in fact, that your client found a hosting plan with PHP and without a database.

jpl80

4:00 pm on Sep 8, 2005 (gmt 0)

10+ Year Member



It's for a department within a University. These departments get their funding from grants. Grants are never guaranteed. My client wants to make sure that they are not stuck with a bill next year that they can't pay for. And I already know how ridiculous this whole thing is, be glad you're not the one stuck with it. If I told you the scope of the whole project, you would probably insist that I call my client and turn down the project... which I may not be far away from doing actually...