Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back button doesn't refresh page if URL contains GET parameters or trailing slash?

I have a CodeIgniter site that assigns users a UUID when the landing page is hit. Reloading the landing page will assign a new UUID, but once you start progressing through the forms your UUID remains the same. However something is happening I don't quite understand when the user hits the back button, and the behavior is different depending on what URL they arrived with?

Case 1: domain.com/somehash?key=value OR domain.com/somehash/

If you arrive with the above url containing a GET parameter, submit the first form (which contains your uuid), and press the back button, you return to the landing page but your UUID does not change.

Case 2: domain.com/somehash

With no GET parameters, if you submit the first form (which contains your uuid) and press the back button, you return to the landing page and receive a NEW uuid.

I tested this in the latest Chrome and Firefox, is it linked to some kind of caching strategy they implement? Ideally hitting back would NOT refresh the page.

EDIT: I should note we can't use cookies for this tool, so sessions are out

Further edit: Simply going to domain.com/, adding a backslash, stops the UUID from refreshing when hitting the back button. Possibly related to CodeIgniter routes.php or .htaccess?

Relevant .htaccess entries:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [L]

Routes.php:

$route['default_controller'] = "home";
$route['404_override'] = '';

$route['(:any)'] = 'home/index/$1';
like image 579
xref Avatar asked Nov 12 '22 06:11

xref


1 Answers

Try setting these headers and see if that makes the behavior consistent in both scenarios:

$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");
$this->output->set_header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

More info: http://ellislab.com/codeigniter/user-guide/libraries/output.html

like image 57
Justin Avatar answered Nov 14 '22 23:11

Justin