this is crossing my mind and I\'m wondering if it is possible, how secure can it be to store info in the $_SESSION variable of PHP?
The $_SESSION
is stored entirely on the server, so the user cannot modify it. However, it is possible for session-hijacking exploits where the user gets connected to another user's session.
PHP Session's work by storing a PHPSESSID
cookie on the end user's computer that acts as an access key for server-based session information. That cookie value is a hashed string (the security of which depends on your PHP settings) that is used to link the particular browser to the specific session values you set.
That string looks something like b420803490a9f0fe8d6a80657fec3160
. So, the end user could alter that string, but then their session will become invalid, since it almost certainly won't match one that's being stored by PHP, and they won't have access to data.
There is a risk, as others have mentioned, that someone's PHPSESSID
become exposed, and people use that to hijack someone else's session.
Where as less secure $_COOKIES
are on the client computer, the $_SESSION
is stored on the server. It's location is determined by the session.save_path
of php.ini. However there are still security issues such as session fixation
Storing variables in the $_SESSION variable has two potentials for "insecurity".