最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

setting cookie through JavaScript vs setting Cookie through PHP - Stack Overflow

programmeradmin4浏览0评论

I was wondering is there any clear advantage of setting some cookie though JavaScript in client side pared 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?

I was wondering is there any clear advantage of setting some cookie though JavaScript in client side pared 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?

Share Improve this question asked Jul 23, 2012 at 3:01 DavidDavid 4,8188 gold badges37 silver badges42 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 4

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.

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

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

发布评论

评论列表(0)

  1. 暂无评论