One cookie with many values or many cookies with one value?

前端 未结 4 402
慢半拍i
慢半拍i 2021-02-07 06:43

If I have many settings that I want to store in a cookie, should I create multiple cookies with one option each, or one big cookie with multiple options in a serialized array or

4条回答
  •  滥情空心
    2021-02-07 07:08

    Your options are:

    PHP Sessions - No cookies required. Store all the data you want. Once the browser is closed or the session is closed new authentication is needed.

    Persistent Sessions - One cookie with one value which is either the session key used to access stored sessions or used to access a database table with session information. You can store all the data you want and you have the benefit of not worrying about signing in all the time.

    Cookie Only - Storing multiple values in a cookie is not always the best of ideas. Why? 1) Cookies are insecure and can be read by anyone. 2) keeping up with multiple cookies throughout your application can be a source of future bugs. 3) Depending on the client/browser to provide you with accurate data is never good. If you use cookies, make sure they have as light of a footprint as possible.

    Big cookies only give you a tummy-ache. Eat Cake instead.

提交回复
热议问题