Chrome and sessions
Posted: Wed Jun 16, 2010 3:05 pm
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
In checkout
And this is executed near the start of every page load, note the first block is new and now works.
$_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.
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;Code: Select all
if($_SESSION['checkoutStage'] == 0) {
//redirect
}
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;
}