Welcome Guest, Not a member yet? Register   Sign In
How to refresh page when back button of browser is clicked
#1

[eluser]rei[/eluser]
Hi, how to reload page when back button is pressed? Or how can I let users see fresh content of page when they clicked the back button of the browser? I need solution for this because in my online exam system, I'm displaying 1 question at a time and users are not allowed to go back to previous question. The problem is when they press the back button of the browser it displays the previous page because the page is being cached by the browser. Even if I set a $_SESSION['current_question_number'] its useless because when I press the back button of browser it doesn't re execute the php code. Please give me suggestions/ideas how to solve this.Thanks! Smile
#2

[eluser]pzajdler[/eluser]
You can simply open your tests in new window containing no toolbar (thus no back button), I find it the most simple solution for your problem
#3

[eluser]mr_prasanna[/eluser]
Even though, hiding toolbar sounds like a simple solution, users can still use keyboard shortcuts I guess.


1. Set expires/cache control properly, so that browser always requests server for a fresh copy. [this is a little tricky between various browsers.]
2. Switch to AJAX to load questions. This might help.
#4

[eluser]PhilTem[/eluser]
@mr_prasanna is right: The only thing that will really work (and I guess isn't such a hustle to set up) is to use expires/cache control and refresh-required properly. Even with AJAX I think it's not that easy, since you would have to change your whole page to be AJAX-compatible (like e.g. Facebook and G+ do). And this can be a real pain in the you-know-where Wink
#5

[eluser]rei[/eluser]
Thanks guys for your replies and suggestions. Nwei I tried the solution of setting the cache to expire to always load fresh content. But when I tried to press the back button FireFox tells me that the session has expired. And in Opera Mini it still loads the previous question because it is not re executing the php code even if i put $_SESSION['current_question'] its useless because the browser is not reloading so the code deosn't re execute.

Nwei im using this php code

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
#6

[eluser]PhilTem[/eluser]
The correct way to set the headers appropriately is

Code:
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

I read on stackoverflow that this should actually work if you do it like

Code:
header('Cache-Control: no-cache, no-store, must-revalidate'); // HTTP 1.1.
header('Pragma: no-cache'); // HTTP 1.0.
header('Expires: 0'); // Proxies.

though you want to use the CI-output class rather than setting the headers directly (because of the dataflow)

Or, as stated on daniweb.com

Code:
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");

Googeling sometimes really helps Wink
#7

[eluser]rei[/eluser]
@PhilTem --- Hi sir. thanks for your help. But still no luck. I'm using firefox browser and when I added the code you provided firefox shows me an error when I click the back button --

Document Expired..
This document is no longer available.
#8

[eluser]rei[/eluser]
UP.

Anybody knows a solution for this problem?
#9

[eluser]InsiteFX[/eluser]
Search for jQuery History.js plugin
#10

[eluser]rei[/eluser]
thanks for your reply Smile But do you have an idea to do it in just plain PHP? because using javascript for security purposes is not secure because a user can easily turn off the javascript in their browser. I need it to be secure because I will be using it in an online exam system.




Theme © iAndrew 2016 - Forum software by © MyBB