GET rid of a page from browser history - php

I have a page for example, say first.html. it has a form with action set to, say xyz.php.
This php file ,after processing , sends a header () with location . Now browser fetches the page.
Now when I click back button ,first.html shows.
Is there a way to get rid of that first.html page and show other page from history?

When there's a redirect if you want to replace the page that triggered the redirect you can use window.location.replace(newUrl).
Here's the documentation for replace

Related

document expired after pressing back button

I have a page called a.php . It has a form and submit data via POST to same file (a.php) . Page loads with no error. Then I click any link (b.php or b.html) on that page . it directs to any page as usual. Then when I click back button from b.php or b.html it does not show previous page.
Any help to solve this matter ?
Thanks
About Method
The $_POST Method used for SUBMITTING FORMS something Create or Modify it is a secure method.In other words POST is sending data to server from browser
FOR EXAMPLE
Creating Articles
Editing Articles
File Uploading
In your case you are getting values POST is not for getting values Use $_GET method for this
Why Document Expires ?
I taken this Image from wikipedia.
Why Browser Do this?
It is because it prevent from duplicate submission.
For Example : On any shopping site there are payment options user buy a product and pay for it , now if he/she(user) refresh page again the payment done two times .
according to your question, page a.php is submitting data (post) to the page itself, so if you go to other page and then want to back again to page a.php (by clicking the back button on browser) it causes document expired because when you click it you are not submitting any data (post) to page a.php.

How to reload page containing POST data

I've got a section on every page of my site which allows the user to set a reminder. It loads the appropriate form on the page when the $addtracker variable is set in the url using:
$current_url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";?>
Add reminder
It works on every page except pages which rely on POST data, such as a search results page. When the link is clicked on these pages, the POST data disappears and so I get 0 results in the search and $_POST data not found errors.
How can I reload the current page with the POST data intact?
You should use form with method="GET"
Do not use link , use form with button.

How can i prevent repeat submit when i refresh web page?

My situation:
On the html page i click the button to submit my form . And after process of php , send back the result to html page and bring out . But when i refresh my page , and pop-up the window and ask me whether or not send the form data again . But now i don't want to let this window appear , i google and get some solutions , redirect or the others , but my problem won't be solved. How can i do for my problem .
Notice: I will use the data of the php process and send back , so i can use the redirect method .
Thanks all .
The simplest solution is to split your page into 2 parts.
The first part presents the page to the browser but instead of submitting back to the same page you submit to another page. Once that page has done what is required with the data from the page you redirect to the original page.
So page xxx.php collects any data required before presenting the page to the browser and has an <form action="xxx_upd.php"....>
And page xxx_upd.php just reads $_POST or $_GET and processes the input, once complete it does a header( 'Locaction: xxx.php' ); to cause the first page to reload but as it has been reset to initial state by this process it will not cause the message when you refresh the page and will not try to re-run the processing which is now done by xxx_upd.php

Session save delayed in php

I have the following problem: I have two pages. In the first page is a button. When the button is clicked, an ajax request is made to a page that saves data to the session. Then, it redirects me to the second page in which I display this saved data. The problem is that when I go to the second page the data is not displayed, but when I refresh the page the data is displayed. How can I redirect to the second page with the session data stored?
Example:
Before Refresh:
After:
Does anyone have any ideas?
You should wait for the response of the AJAX request before you forward to the next page.
Preferable use the callback method to redirect to the next page.
If you post some code may be it will be easier to point out.
Try this, hope it'll work
if you are using jQuery then fine, use e.preventDefault(); and redirect your next page after getting the ajax response.

Stay on current page after POST

I have a form which once the Submit button is pressed, it goes to a blank page and returns any error messages on that blank page. However I have a website template and I wish that my script is run, and returns the the page which did the action POST and puts any error messages on that page.
Example of what is happening:
PAGE REQUESTS POST ----> SCRIPT RUNS ---> RETURNS ERROR MESSAGE
What I want it to do is:
PAGE REQUESTS POST ---> SCRIPT RUNS ----> GOES TO THE PAGE WHICH REQUESTED POST ----> SHOWS ANY ERROR MESSAGES WHICH THE SCRIPT PICKED OUT.
Sure you can, just set the Action of your form to the current page. Then the $_POST will contain all the values the user filled in the form.
You have two options. I assume your are going to a blank page, because your POST goes to a PHP script different from the page it is posting from.
Option 1 - Post to the same PHP page as the page your are posting from.
Option 2 - Once you have posted, and generate an error, redirect back to the page, with the errors stored in a session, or a cookie, so that they can be rendered on the original page.
Assuming that the page containing the request form is also able to display the error messages, set the form attribute to the url of the page containing the form (as TJHeuvel noted) or just make action attribute empty, e.g, <form action="">.
After going to blank page store all the posted variables in your variable say $get with syntax param1=value1&param2=value2 and so on...and redirect back by header("Location: back.php?$get"); and in your main page by $_GET echo all the vars

Categories