Cookies - PHP vs Javascript

前端 未结 6 1098
面向向阳花
面向向阳花 2021-01-01 12:35

With regards to security and convenience which cookies are better the PHP ones or the Javascript ones?

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-01 13:13

    They are the same ones, in both cases the cookie is sent to the browser, stored there and the browser send it back to you every request until it expires or is deleted.

    For that reason, you should never use cookie for security as your question implies nor for any data which you consider important to keep unaltered by the end user.

    There are five things to always remember when you use cookie:
    1 - you can not trust its content
    2 - you can not assume it will still be there on the next request
    3 - you can not trust its content
    4 - you can not assume the user never visited before if it's not there
    5 - you can not trust its content

    If you get that, accessing cookie from php or javascript is simply a question of what's more convenient to you.

提交回复
热议问题