I have several questions about PHP sessions:
I am expecting my Apache server to remove old php session data from server automatically, when the session expires. Is this a setting somewhere in PHP or somewhere else in the server? For example, I have the expiretime already set to 15 minutes, and after a session expires, I'd want this to be deleted from the server, to prevent the build up of 100 thousand session files:
$expireTime = 60 * 60 * .25; // 15 minute expire time
session_set_cookie_params($expireTime,"/");
To prevent fixation, I do the following on every single page load in the WebApplication:
session_start();
session_regenerate_id(); // Prevent Fixation: Regen session ID every page load.
Which leads me to another question - if I regenerate the session ID every time (and because I do this, I create a new session file on my server) - can I somehow delete the previous session file safely, immediately? Or is this bad practice all together?
I plan to store a lot of base user information in the session - is this bad practice right away? Information includes:
- Several ID's related to various permissions in the system. I would do checks on every page to see that their session ID matches an ID of information that is being displayed. BUT - if a user can somehow change their session data, this is obviously not going to work.
- User first/last name, and email address
- Other base information about the user, used for display only.
I plan to implement IP Checks, so that before the above code, the serve checks the current IP ( $_SERVER['REMOTE_ADDR'] ) and verify it matches the previous IP. If not, I redirect to the login page. If it does, then we can continue on and regen a new session ID as listed above... Thoughts on this?
Is there anything I'm missing for having an accepted Session security solution?