Possible Duplicate:
Preventing session hijacking
I am coding up my login and authentication system for a PHP
web application and looking for best practices to prevent session hijacking. The login page set's sessions:
$_SESSION['email_address'] = $_POST['email_address'];
$_SESSION['ip_address'] = $_SERVER['REMOTE_ADDR'];
Then in every page and action I check to make sure the session exists, and the ip address stored in the session matches the ip address in $_SERVER['REMOTE_ADDR'].
if(isset($_SESSION['email_address']) && isset($_SESSION['ip_address']) && $_SESSION['ip_address'] == $_SERVER['REMOTE_ADDR']) {
//valid auth
}
Reading online though, some people say simply checking the ip address is NOT good enough. What else is needed? Also, there is talk of using session_regenerate_id()
. How does that factor into my code? Do I call session_regenerate_id()
on every page?
Thanks.