Is it possible to change the address of the back button in the browser? For example I am in this page:
http://website.com/page3.php
I submit a form and it returns this address:
http://website.com/page3.php?ok=ok
After which when I go to another page, for example
http://website.com/blog.html
and click the back button, it goes back to the page with $_GET variables on it.I want it that when I click the back button of the browser to go here:
http://website.com/page3.php
Is it possible for the back button (of the browser) that everytime I click it whenever I just came from that specific page with variables, it wont get the variables as well?
I think you can set a session variable on your form in http://website.com/page3.php. and then unset it once the submission is done in http://website.com/page3.php?ok=ok.
and each time the page with the variable in the url is loaded, check immediately for the submission session variable to see if you are redirected to the page from the form page. and if not, redirect you back to the page3.page.
I hope I made myself clear enough!
This is not possible you can hack something together by using pushState and playing with the browser history
One method would be to do the form post request using AJAX.
Another one would be to add tokens to your forms and check them server side to redirect using header() if they don't exist. Eg :
<?php
session_start();
if(isset($_GET['ok'])){
if(isset($_SESSION['form_page3_token'])){
$_SESSION['form_page3_token'] = null;
//first request : do your stuff
}else{
//repost (F5 or Back in the browser => redirect to origin form)
header('Location: http://www.website.com/page3.php');
}
}else{
$_SESSION['form_page3_token'] = session_id();
//here the code to show the form
}
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With