The title of this question kind of explains my question. How do I redirect the PHP page visitor back to their previous page with the header( "Location: URL of previous page" );
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Just try this in Javascript:
Or you can try it in PHP:
You have to save that location somehow.
Say it's a POST form, just put the current location in a hidden field and then use it in the
header()
Location.try:
Note that this may not work with secure pages (HTTPS) and it's a pretty bad idea overall as the header can be hijacked, sending the user to some other destination. The header may not even be sent by the browser.
Ideally, you will want to either:
Its so simple just use this
Its working fine for me
Just a little addition: I believe it's a common and known thing to add
exit;
after the header function in case we don't want the rest of the code to load or execute...Storing previous url in a session variable is bad, because the user might right click on multiple pages and then come back and save.
unless you save the previous url in the session variable to a hidden field in the form and after save header( "Location: save URL of calling page" );