Skip to content
Advertisement

How can I encrypt a cookie value?

How can I encrypt, and later decrypt, a cookie value in PHP? How secure will the encryption be?

Advertisement

Answer

I can not simply think of a situation where encrypting data in the cookie is useful. If you want to retain secret data about the user or his preferences, information, whatever, then store it on the server in files, in the session or in the database, but not in the client’s computer.

On the other hand, if you creating an authentication, then you should use sessions instead of creating secret encrypted cookie values. Sessions weren’t implemented for nothing, they are the way to go.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement