Encrypting cookies in PHP

后端 未结 5 2034
梦谈多话
梦谈多话 2021-01-11 15:48

How can i encrypt and later decrypt a value of a cookie in PHP (how secure will the encryption be )

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-11 16:07

    I can think of a reasonable use for this. Suppose you have a large server farm, you're going to have a bottleneck at the database and/or memcached server for handling session requests.. "is this user logged in?"

    If you were to store the users session data as an encrypted value in the cookie, then you can prevent having to do quite a few read/writes and allow for an unlimited sized cookie store since there is 0 impact on your side other than being CPU bound for encryption/decryption of the cookie data.

    Ruby on Rails by default does this - although it only signs the data and does not encrypt it. There is an alternative implementation which encrypts the data with its own key and signature so you the user is not able to see what data you store in their session.

提交回复
热议问题