simple cookie question - best way to do this

Joined
12 Feb 2006
Posts
17,312
Location
Surrey
i want to make it so after someone gets a quote with us, some of the basic information is stored as a cookie so that the user can come back later and view the list of quotes they got.

all i need is roughly the below information stored.

Quote Id
name
date wanted
total price
security token.

having never really worked with cookies before, what would be the best way to store this?

the user may get 3/4 quotes, and i want it so that when they return, i can show a list of the quotes they received last time showing the above information.
 
Associate
Joined
21 May 2013
Posts
1,991
Cookies don't sound like the right solution for this.

They're for adding minor enhancements, not storing critical feature data.
Imagine how your customer would feel when suddenly one day all of their orders have been "deleted".

I think maybe some kind of combined approach like kitkat's suggestion would make the most sense: implement the feature server-side and use some kind of access token to provide the enhancement on the client side. That way you can restore "lost" orders or provide a different method of access since you control the data source completely.
 
Last edited:
Soldato
OP
Joined
12 Feb 2006
Posts
17,312
Location
Surrey
Cookies don't sound like the right solution for this.

They're for adding minor enhancements, not storing critical feature data.
Imagine how your customer would feel when suddenly one day all of their orders have been "deleted".

I think maybe some kind of combined approach like kitkat's suggestion would make the most sense: implement the feature server-side and use some kind of access token to provide the enhancement on the client side. That way you can restore "lost" orders or provide a different method of access since you control the data source completely.

I do this too. I just need to store the information locally so that when they go to the site say 5 minutes later, the say 3/4 recent quotes they got they can see the basic list of them, then when they click, it then queries the database for the full quote information to be viewed. none of the information being stored by the cookies would be critical.
 
Associate
Joined
10 Nov 2013
Posts
1,808
As others have said, this is not what cookies are for. You should be querying the db for a list of someone's recent orders and querying the db when they choose to view an order.
 
Soldato
Joined
24 Sep 2007
Posts
4,912
What about take their e-mail address when they get a quote, then automatically e-mail them a copy of the quote.

Save any quote to the database.

Ask them for their e-mail if they want to retrieve quote history.
 
Associate
Joined
21 May 2013
Posts
1,991
I do this too. I just need to store the information locally so that when they go to the site say 5 minutes later, the say 3/4 recent quotes they got they can see the basic list of them, then when they click, it then queries the database for the full quote information to be viewed. none of the information being stored by the cookies would be critical.

What is your website built with? You could possibly implement this using PHP session data or localStorage depending on required browser support.

The way I see it, using cookie data you would need to read the anonymised token from the cookie, asynchronously request the abbreviated quote data from the server and then finally update the interface.

If your site was already using PHP, utilising session data would skip the first two steps entirely.

I would probably implement this using localStorage. Store the abbreviated quote data and ID locally, but require the user to click through to a full view where the data is requested from the server before any confirmations are made. However this may not be feasible depending on browser support needed and sensitivity of the quote data.

Personally, if I were collecting quotes from various companies I would expect a confirmation to be emailed to me so that I could use/arrange them as I liked, with an quote ID/contact info should I need to talk about it with the company. I wouldn't usually return to a company website to review a quote I received, unless I wanted to proceed with it - in that case I think a link included in the email would be the most convenient.
 
Last edited:
Soldato
OP
Joined
12 Feb 2006
Posts
17,312
Location
Surrey
As you have the info in the database, why not just query the database for the list of recent quotes?

with what? how would i know their recent quotes? surely after they get a quote, storing the quote number as a cookie so if the user returns 2/3/4 days later then having it right there is better way to do it.




What about take their e-mail address when they get a quote, then automatically e-mail them a copy of the quote.

Save any quote to the database.

Ask them for their e-mail if they want to retrieve quote history.

i do have a way for users to get previous quotes and do all this already, but i also want a way for a user to have the quotes they get stored so that they are listed and reminded of these quotes when on the site and can easily see them without having to add steps for no reason.


to be honest, this is exactly what i thought a cookie was for.
 
Soldato
OP
Joined
12 Feb 2006
Posts
17,312
Location
Surrey
What is your website built with? You could possibly implement this using PHP session data or localStorage depending on required browser support.

it's built using php and mysql.

The way I see it, using cookie data you would need to read the anonymised token from the cookie, asynchronously request the abbreviated quote data from the server and then finally update the interface.

If your site was already using PHP, utilising session data would skip the first two steps entirely.

wouldn't this only apply for the current session, and gone when they come back say 2/3 days later?

I would probably implement this using localStorage. Store the abbreviated quote data and ID locally, but require the user to click through to a full view where the data is requested from the server before any confirmations are made. However this may not be feasible depending on browser support needed and sensitivity of the quote data.
that's exactly what i'm saying i want to do.

Personally, if I were collecting quotes from various companies I would expect a confirmation to be emailed to me so that I could use/arrange them as I liked, with an quote ID/contact info should I need to talk about it with the company. I wouldn't usually return to a company website to review a quote I received, unless I wanted to proceed with it - in that case I think a link included in the email would be the most convenient.

that is exactly what happens already.
 
Soldato
Joined
29 Aug 2010
Posts
7,904
Location
Cornwall
You don't want to be storing personal information in a cookie (such as name).

I agree with storing the ID in the cookie and getting the rest out of the DB using the Quote ID.

If you really want to store that info in a cookie, then consider storing the cookie server-side rather than client-side.
 
Back
Top Bottom