Reputation: 4818
I was wondering is there any clear advantage of setting some cookie though JavaScript in client side compared to use of setcookie() function in PHP? The only reason i can think of is reducing some network traffic (First time). but its not very clear is there any other advantage?
Also if i am using Cookie (created by Java-Script calls) to retain the portion of information which i want to set at the client level (some custom look and feel) will this cookie sent to server with each HTTP request?
Upvotes: 0
Views: 2704
Reputation: 8348
They are basically the same. In both cases the cookie is sent to the browser, stored there and the browser sends it back to the client with every request until it expires or is deleted.
Also, here are some similar questions you could use for more information (I wouldn't call these exact duplicates, though):
Cookies - PHP vs Javascript (where quote is from)
Javascript cookies vs php cookies
Differences between php and javascript cookies
Upvotes: 2
Reputation: 3081
There is no difference between php and js cookie, they are same. the difference is just from where they are created. if you set a cookie from server it will be sent with headers and will be available when next time you load the page. but with js cookie will be available instantly. other than that every cookie goes back and forth with the headers
Upvotes: 4
Reputation: 9262
Cookie should still be sent with every request, even if set by javascript.
Only real reason I can think of to set a cookie by javascript is if your saving something modified client side - like the custom look and feel you mentioned.
Upvotes: 4