Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP MySQL
I'm developing an online shopping site. The site isn't real, it's just a proyect for my portfolio and for personal learning. I'm a little stuck on the shopping cart subject becuase I do not know what's the best way to proceed. I've noticed that most websites save your cart even if you're not logged in, even if you don't have an account, even if you close your browser and come back later. I've thought of a few things, but I have a few doubts on each and I haven't been able to find what is the best way of doing it. These are my options:
  1. Session variables. I could start a php session variable but that would only work for the current session (I think?).
  2. Database table. I could set a temporary table on my database to keep that cart info for users whether or not they've created an account. To do this though, I'd have to find a unique way of identifying each client (for those with no accounts) and I haven't the faintest as of to how to do that. I know IPs won't work beacuse people log on into different routers all the time, and all those sharing a router would share an IP address. If there is a way though, I would very much like to know.
  3. Cookies. At the moment, this seems like the best idea, as long as the user opens up the site on the same browser on the same device. The disadvantage is, that some people like to configure their browsers to block cookies. Plus, if the user erases the browser history including the cookies, it's gone.
If any of these (or any combination of these) is the right answer, please point it out, or if I'm missing something. Am I on the right track?
 
P.S. I know there are a few free third-party-solutions but I would really like to do this myself, just for the heck of it.
Posted 26-Nov-12 20:50pm
Vic91421
Edited 26-Nov-12 21:19pm
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You are going in the right direction. Shopping Cart is a kind of application which includes all the basic stuffs to learn and explore.
 
As you said, making use of JavaScript Cookies is an appropriate option. But also, there is another storage mechanism - localStorage, in JavaScript. Using this, you need not to worry about the browser cookies cleared by the users. For more details please refer to the site - jstorage
 
Have a happy coding !!!
 
Regards,
Niral Soni
  Permalink  
Comments
Vic91 at 27-Nov-12 12:50pm
   
Thanks! This is very interesting. I have a different concern now in which I hope you can help. What is the propper way of designing a web site structure, and by this I mean, the relationship between static web pages and dynamic web pages? Say I have a page called view_product.php that I use to access the database and display the information of a certain product, and I use it to view ALL products. Is this right? Because I understand search engines don't like this. I've seen on most web sites that when you access a specific post per say, it usually is a static page, and that makes sense to me, otherwise I don't know how the search engines would find it. I read something that I want to try, and that is caching static pages from the dynamically generate page. Do you have any insight on the subject?
Niral Soni at 30-Nov-12 10:26am
   
When you are dealing with the dynamic web applications, there is always issues related to the search engines, how they would find contents of your website (products, categories etc). I myself have never tried to create a website publiclly accessible, but from my understanding, there are some configurations you need to made on your web server which will allow your dynamic page contents to be searchable. You also need to improve your page ranking so that your site reaches to more and more people. check this url - (http://www.googleguide.com/improving_pagerank.html)
 
Google has provided its own configuration so that your pages can come in the search results.
 
Hope this helps you out...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 851
1 OriginalGriff 390
2 CPallini 265
3 George Jonsson 191
4 Kishore Pogaru 160
0 OriginalGriff 5,450
1 Sergey Alexandrovich Kryukov 4,532
2 CPallini 4,500
3 George Jonsson 3,102
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 27 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100