0

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?

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

HTTP cookies might also be good to mention here since we're talking clientside vs serverside.
4

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

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.