Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Updated 26-Nov-12 21:19pm
v2

1 solution

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
 
Share this answer
 
Comments
Vic91 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900