javascript - Best way To handle a Cookie -
I'm a newbie in developing web applications and want to learn best practices, I want to know how to handle cookies What is the best practice, should the data be used in JavaScript or PHP to handle any cookie data?
1. Do you use JavaScript to get the cookie and pass it to PHP to filter all?
2. Do you use PHP to do all the things?
3. Any one of the above will get better performance or is there any other way?
Should JavaScript or PHP be used to access cookie data?
To make it a little more common, call it "Client Side" (which is almost exclusively javascript) and "Server Side" (which can be in PHP, Javascript or any other language) code.
The short answer is that: It depends on what you are doing cookie data.
Officials At times, cookies are easy to deal with server side.
Occasionally, information in the cookie needs to be secure, and you do not need to access it with the client-side code, So that if you are limited to harming XSS attack.
Sometimes you want to avoid server round trip (to take a trivial example): You can use the user for your website Different styles You do not want to reload the whole page when they change their choice. You use the client side code to replace the currently loaded stylesheet, and in that cookie, the priority Use the client side code to archive. In the future, when other pages are loaded, you can use the server side code to set it separately
& lt; Link & gt; element.)
Do you use javascript to get cookies and pass it to PHP to filter all?
You can use the client side code to set a cookie value, and then use the server-side code to read it. It does not make sense to use JavaScript to read it and then use some non-cookie based system to send server-side code. It just makes things complicated and is more likely to be wrong.
Do you use PHP to do all the stuff?
Only if all the stuff is better with PHP
Which one of the above would improve or is there any other way?
Client side code vs. server side code: If you are not loading a new page anyhow, using client-side code is usually faster.
Comments
Post a Comment