Mozilla chokes on cookies (Developer MUST READ!)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Mozilla chokes on cookies (Developer MUST READ!)

Post by chrys »

I may have found a problem with Mozilla and cookies (in turn, PHP sessions).

I have tested with both Mozilla and IE.

When I connect to a page, say, http://www.internationalscholarships.com/cobrand/, and I click a few links, it starts to "lag out". You won't be able to load another page in the entire site until you clear your cookies. I have struggled to find the problem in my code that caused this. The problem went away when I removed session_start() from the header file.

Great news, now I have a hint as to what's causing this. So, for some reason I started to become suspicious of the way Mozilla Firefox handles cookies. I loaded up IE and connected to http://www.internationalscholarships.com/cobrand/. I could click around flawlessly, the page never took more than a split second to load. I went back to Firefox and tried again, and it lagged up again after the first page load.

While I want to say that it's Firefox that's causing this problem, I don't see it happen on any sites other than my own (as far as I know). Has anyone had any experience with such a problem? Anyone have any related info?

I would greatly appreciate any assistance in getting to the bottom of this.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ignoring that your page starts right into the body tag without any header or other precursor stuffs, your page sets no-cache. Firefox will retrieve a new copy of everything on every page load, thus making it run extremely slow.

Code: Select all

[feyd@home]>php -r var_export(get_headers('http://www.internationalscholarships.com/cobrand/'));
array (
  0 => 'HTTP/1.1 200 OK',
  1 => 'Date: Tue, 04 Oct 2005 15:05:09 GMT',
  2 => 'Server: Apache',
  3 => 'X-Powered-By: PHP/4.4.0',
  4 => 'Set-Cookie: ISCH=hexdata; path=/',
  5 => 'Expires: Thu, 19 Nov 1981 08:52:00 GMT',
  6 => 'Cache-Control: private',
  7 => 'Pragma: no-cache',
  8 => 'Connection: close',
  9 => 'Content-Type: text/html',
)
edit: after poking around for a bit, it appears that it's more a problem with your server. Specifically, it appears that the server is trying to actively cache data for a given IP or something (possibly a view table)
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

feyd wrote:ignoring that your page starts right into the body tag without any header or other precursor stuffs, your page sets no-cache. Firefox will retrieve a new copy of everything on every page load, thus making it run extremely slow.

Code: Select all

[feyd@home]>php -r var_export(get_headers('http://www.internationalscholarships.com/cobrand/'));
array (
  0 => 'HTTP/1.1 200 OK',
  1 => 'Date: Tue, 04 Oct 2005 15:05:09 GMT',
  2 => 'Server: Apache',
  3 => 'X-Powered-By: PHP/4.4.0',
  4 => 'Set-Cookie: ISCH=hexdata; path=/',
  5 => 'Expires: Thu, 19 Nov 1981 08:52:00 GMT',
  6 => 'Cache-Control: private',
  7 => 'Pragma: no-cache',
  8 => 'Connection: close',
  9 => 'Content-Type: text/html',
)
It jumps right into the body tag because it's to-be-included, so maybe this is a bad example. Just plain http://www.internationalscholarships.com also has this issue, and other various applications I've created (only on these specific servers).

I will set the Pragma and Cache-control and observe the changes. Please note that this only happens in Mozilla, while IE is blazing fast to load pages. Mozilla will now and then "choke on a cookie" and lag up until I clear cookies and reload the page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I checked in both for quite a while.. For me Firefox only choked on the second load (clicking to get a detail) the first time.
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

feyd wrote:I checked in both for quite a while.. For me Firefox only choked on the second load (clicking to get a detail) the first time.

Right, that's what happens to me too... How bizarre?

Where the cobrand is actually used: http://www.iefa.org/search/

It doesn't choke. Now, this was a very frequent choking incident, and it may be related to not having <html> <head> or <body>. But, in sites that do have the proper structure, it still happens to me, but infrequently. Considering that my application is used all day by people, it may happen to them once or twice throughout the day and can prove to be annoying to them.

We have 3 servers at my company, namely "1", "2", and "local". This problem appears to happen on all three of them, with my code, only in Mozilla. You can only imagine the kind of stress! :)

Do you have any suggestions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

all I can say is there's likely something goofy in the site code that does it.. the cookies are fine from what it looks like...
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

feyd wrote:all I can say is there's likely something goofy in the site code that does it.. the cookies are fine from what it looks like...
Alright, so let's explore this problem a little further.

What we know:

This problem happens in Mozilla only, and never IE.
This problem happens in my sites only, no other sites that I know of.
This has happened on 3 seperate servers.

For now, let's assume there is some code doing this.

All of my sites use the same codebase for session management. Here are some snippets:

Whenever a user loads a page, this is what generally happens:

Code: Select all

$user = new User;		// User/Session class

$user->Update();
$user->loadUser();
Here is what you need to see from the User class:

Code: Select all

function Update()
{
    session_name("Protege5");
    session_start();
}
This function is a bit more bulky, but I have commented it thoroughly

Code: Select all

function loadUser()
    {
		/* Load some information provided to us by the client */
        $this->info['ip'] = 		getenv( "REMOTE_ADDR" );
		$this->info['cookie'] = 	getenv( "HTTP_COOKIE" );  // This may be problematic, will remove after I paste this code
		$this->info['user_agent'] = getenv( "HTTP_USER_AGENT" );
		$this->info['referer'] = 	getenv( "HTTP_REFERER" );
		
		/* If the user is logged in, fetch all of his/her data
		   from the database and load it into the class */
		   
		if( $this->isLoggedIn() )
		{
			$sql = "SELECT *
					FROM   staff
					WHERE  id = " . $_SESSION['user_id'];
					
			$result  = $this->query( $sql, "", __FILE__, __LINE__ );
			
			/* A foolproof to make sure that if there is no user,
			   none of these things happen. */
			if( mysql_num_rows($result) )
			{
				$row = mysql_fetch_array( $result );
				
				while( list( $key, $val ) = each( $row ) )
					$this->$key = $val;
				
				/* Assign a title based on user access level */
				switch( $this->acl )
				{
					case "1":
						$this->title = "Superadmin";
						break;
					case "2":
						$this->title = "Manager";
						break;
					case "3":
						$this->title = "Customer Rep";
						break;
					default:
						$this->title = "Other";
						break;
				}
				
				/* This segment inserts a record into the 'sessions' table
				   which keeps track of where a user is within the
				   application.  */
				
				global $page_title;  // This is set on every page
				$url = getenv("SCRIPT_NAME") . "?" . getenv("QUERY_STRING"); // Exact location
				
				$sql = "UPDATE sessions SET 
							title = '$page_title',
							url = '$url',
							lastaction = '" . date("Y-m-d H:i:s") . "',
							lastsearch = '$_SESSION[lastsearch]',
							lastapp = '$_SESSION[lastapp]',
							avgload = '$_SESSION[avgload]'
						WHERE  user = '$this->username'";
						
				$this->query($sql, "sessions", __FILE__, __LINE__); 			
			}
		}
    }
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

I'm not getting any lag on firefox on mac os 10.4.

Hope that helps.
User avatar
chrys
Forum Contributor
Posts: 118
Joined: Tue Oct 04, 2005 9:41 am
Location: West Roxbury, MA (Boston)

Post by chrys »

neophyte wrote:I'm not getting any lag on firefox on mac os 10.4.

Hope that helps.
I'm figuring that it's Windows Firefox only... hmm.

When I say lag, I mean the page times out. Once the page starts timing out, every page within that site starts timing out. I know it's related to the sessions somehow...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the page doesn't time out for me.. it simply takes a bit of timet load... but it does load.
Post Reply