Dynadot โ€” .com Registration $8.99

Shopping cart

Spaceship Spaceship
Watch

SiKing

Registered MemberEstablished Member
Impact
6
Hey, I'm coding an ecommerce site at the moment. Can anybody tell me whether it's better to use cookies or sessions for the shopping cart application. And in what way? Thanks :]
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Sessions, IMO, are easier to use and since they don't store cookies on the user's computer, (as far as I could tell, I searched through them looking and couldn't find one from the sessions) they are more secure... just store the current user's IP, id number, username, and ENCRYPTED password in session variables. Each page load, check them w/ the database for extra security.
 
0
•••
Thanks. However, I wasn't planning to have a registration system just yet, so anyone can purchase a product without signing up first. (ie, no username and password). How do I register products to the session? (including quantity and category - there is a table for each category in the database)
 
Last edited:
0
•••
Store a session variable that contains the details... seperate values with a special character (or string of characters) and use explode() when trying to access it. That's what I think would work, but there may be an easier way.
 
0
•••
Thanks, I'll give that a go
 
0
•••
I think I may need a little more help. :s I have no idea how to do this. I started by storing the session id in a database but that just...failed...miserably. lol, thanks for any help I may recieve
 
0
•••
Another cool thing about storing the data in the database is that it allows for you to "leapfrog" domains by passing the session ID on the querystring.

You can save the session id in a text field. The cart and/or product data specific to the cart should be held in several tables. For example, a cart table to hold general cart info (session id, ip, date created, cart total for easy lookup, etc.). The a products table keyed to the identity column in the cart table. Then a product options table keyed to the identity column in the products table.
 
0
•••
Still not a clue. The problem I found with storing orders in a database is that they can only order a maximum number of products which is stupid. Code snippets would be very useful :]
 
0
•••
The problem you will have when using sessions is system resources on the server. The simplest way to understand a session is pretty much a cookie that is stored on the server instead of the end user's PC. The more users, the more resources being used on the server.

Many hosting services have shopping carts included with their service. If you want a product that works and has already been debugged I would recommend finding an off-the-shelf product like that. If you want to build one because you want to increase your proramming knowledge then you are on the right track.

If it is built correctly a database would not limit the number of products a user can purchase.

Good luck.
 
0
•••
miseria said:
Still not a clue. The problem I found with storing orders in a database is that they can only order a maximum number of products which is stupid. Code snippets would be very useful :]

I'm not sure I understand why you say this. With a database, the limit of products that can be associated with a single order is only limited by your hardware.

It might help if you researched database "normalization" and "JOIN"'s.

I have gone through a ton of eCommerce code from various carts and noticed that many of them do not normalize their database structure, or they limit things by way of ignoring the possibilities of JOINs to extend the capacity (as in when people say "its scalable").

However, make sure that once you are normalizing your tables that you don't go overboard. When I was first starting, I'd normalize the hell out of everything and sometimes it would make my code insane. Sometimes it's better to leave things unoptomized in the database structure to enhance the code that references it.
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back