问题
I'm using a form to submit some post information to a PHP script. After the script finishes, I want it to redirect right back to the page the user came from. Right now I'm just using header() with a static URL. I've found a ton of very conflicting information about this around the internet, so I'm wondering what StackOverflow thinks.
回答1:
Use HTTP_REFERER:
header('Location: ' . $_SERVER['HTTP_REFERER']);
回答2:
access the $_SERVER['HTTP_REFERER'] variable and redirect to this. Should do the trick.
回答3:
the way i would do it is use a session variable to store the current page URL everytime it is accessed.
$_SESSION['last_url'] = <get current url>
replace your static url in the header with $_SESSION['last_url']. Depending on how you implement your PHP, you can use search google for "current url php" or just $_SERVER['REQUEST_URI'] (stackoverflow doesnt allow me to put more than 1 link!)
回答4:
Use REQUEST_URI But watch out for that presiding slash/
来源:https://stackoverflow.com/questions/4282008/whats-the-easiest-way-to-redirect-to-the-previous-page-with-php