Chrome and sessions

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
Mutzi
Forum Newbie
Posts: 1
Joined: Wed Jun 16, 2010 2:19 pm

Chrome and sessions

Post by Mutzi »

I'm having a little problem with chrome (and only chrome) in that, somehow or other, it is causing an additional request and upsetting the flow of logic within my scripts. I'll try to keep this as brief as I can, the problem is solved (badly) with a quick work around, what I'm looking for is how and why this is happening, so I can fix it properly. Any ideas would be appreciated.

This is an ecommerce application, users choose their items, go through a basket page (which calculates postage, tax etc), then checkout. A session variable (checkoutStage) is used to keep track of their access to the checkout, this is set in the basket. They must visit the basket before the checkout and if they navigate away, to any other page the variable is reset. This is to allow them to change their order and have basket calculations performed again. If the checkoutStage variable is 0 when they try to access checkout they are redirected to the basket, which sets it to 1. ie to turn checkout-> other page -> checkout into checkout-> other page -> basket -> checkout.

Chrome will not let anyone beyond the basket and keeps redirecting users back i.e basket->basket->basket... Echoing the session before the redirect shows checkoutStage to be 0, at the end of the basket an echo shows 1. The basket links directly to checkout and other browsers work with it ok.

In the basket there is the line

Code: Select all

$_SESSION['checkoutStage'] = 1;
In checkout

Code: Select all

if($_SESSION['checkoutStage'] == 0) { 
//redirect
}
And this is executed near the start of every page load, note the first block is new and now works.

Code: Select all

//this is the quick workaround
$browser_is_chrome = false;
if(eregi("chrome", $_SERVER['HTTP_USER_AGENT'])) {
    $browser_is_chrome = true;
}

//force user through basket for updated calculation of totals if they navigate away from checkout
if($browser_is_chrome == false && strcmp($m,'checkout') != 0) {
	$_SESSION['checkoutStage'] = 0;
}
$_SESSION['checkoutStage'] is not set anywhere else but these lines, the only possible reason I can come up with is chrome is requesting another page (automatically from the various links available?) after the basket page has reached the browser. I know chrome prefetches DNS entries but am not aware of it doing anything like this.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Chrome and sessions

Post by Weirdan »

You don't have to guess if Chrome is doing additional requests - press Ctrl+Alt+J, switch to 'Resources' tab and see for yourself.
Post Reply