CakePHP session error : User-Agent must be consistent

I noticed some erratic behavior with CakePHP sessions and finally tracked down the error. I have FireBug installed with an extension called FirePHP. When FireBug is enabled, I noticed that my User-Agent tends to vary.

Sometimes my browser’s user agent reads :

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8 FirePHP/0.4

Sometimes it reads :

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8

Whenever the User-Agent changes, CakePHP resets the session. This means that I can’t view 3-4 pages on the site before being logged out.

This is the firebug extension that caused the problem.
https://addons.mozilla.org/en-US/firefox/addon/6149

Here’s a link to an error report on FirePHP’s forums
http://n2.nabble.com/FirePHP-and-CakePHP-Session-Reset-tp4671294ef842658.html

This is a great add-on called HTTPFox I used to track down this error.
https://addons.mozilla.org/en-US/firefox/addon/6647

2 Comments so far

  1. Matt on March 3rd, 2010

    This error can also arise when you have Flash or Java applets which interact with CakePHP, since they have their own user agent strings which don’t match the browser.

    I think this is configurable. In config.php, set “sess_match_useragent” to false.

  2. KevBurnsJr on March 3rd, 2010

    Right on. Thanks for the tip, Matt.

Leave a reply