stefanbund / 311

Interactive Web Development
33 stars 46 forks source link

Storing more then one set of values in a cookie. #26

Closed PatrickMinett closed 7 years ago

PatrickMinett commented 7 years ago

Hi, I am trying to store 2 values that the user provides, however I am having trouble getting this to work.

I believe the error is happening in the setCookie function:

// we are setting the users name and age.

function setCookie(cname,cvalue1,cage,cvalue2,exdays) {
var d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); var expires = "expires=" + d.toGMTString(); document.cookie = cname+"="+cvalue1+";"cage+"="+cvalue2+";"+expires; }

two questions, Can I actually store more then 1 value in a cookie? If so do you see anything wrong with my syntax?

stefanbund commented 7 years ago

Interesting let's take a look during class tomorrow

From Stefan Bund

On Feb 20, 2017, at 2:21 PM, PatrickMinett notifications@github.com wrote:

Hi, I am trying to store 2 values that the user provides, however I am having trouble getting this to work.

I believe the error is happening in the setCookie function:

// we are setting the users name and age.

function setCookie(cname,cvalue1,cage,cvalue2,exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays2460601000)); var expires = "expires=" + d.toGMTString(); document.cookie = cname+"="+cvalue1+";"cage+"="+cvalue2+";"+expires; }

two questions, Can I actually store more then 1 value in a cookie? If so do you see anything wrong with my syntax?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

stefanbund commented 7 years ago

I encourage everyone to take the safe route, and employ very simple, very low risk code that fires on every occasion. Embedding only one value per key/value pair in document.cookie is a technique like this

PatrickMinett commented 7 years ago

Makes sense, I ended up doing just that. I went ahead and created 3 separate cookies which ended up giving me my desired result.

Thanks for the help.

stefanbund commented 7 years ago

👏🏻

From Stefan

On Feb 21, 2017, at 2:27 PM, PatrickMinett notifications@github.com wrote:

Makes sense, I ended up doing just that. I went ahead and created 3 separate cookies which ended up giving me my desired result.

Thanks for the help.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.