0

I have this code:

if (isset( $_SESSION['user_agent'] )) {
    if ($_SESSION['user_agent'] != md5( $_SERVER['HTTP_USER_AGENT'] )) {
        die('Session error.');
    }   
}

Everything works fine. But every time I login (once per 24 hours), I get the error. Is the user agent changing or something?

Thanks for your help.

user1453094
  • 373
  • 2
  • 7
  • 13

2 Answers2

0

Sessions have a limited lifetime http://www.php.net/manual/en/session.configuration.php usually minutes or some hours

Maks3w
  • 6,014
  • 6
  • 37
  • 42
0

Anyone capable of hijacking sessions (i.e. via sniffing unencrypted HTTP) has the keys to the kingdom once an authenticated user comes along.

HTTP_USER_AGENT? Yeah, that's also sent in the clear, and the attacker can just spoof it. Any MitM applicance that steals/spoofs session cookies will generally also impersonate the user agent of the user's browser too.

The only solution here is HTTPS, which is now free thanks to Let's Encrypt.

Scott Arciszewski
  • 33,610
  • 16
  • 89
  • 206