"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Perform PHP Redirection with POST Parameters Without JavaScript?

How to Perform PHP Redirection with POST Parameters Without JavaScript?

Published on 2024-11-08
Browse:747

How to Perform PHP Redirection with POST Parameters Without JavaScript?

PHP Redirection with POST Parameters

The query posed concerns redirecting users from one webpage to another while retaining POST parameters. The original method, which involved transferring GET parameters to POST parameters through a form, was deemed suboptimal, especially for users with JavaScript disabled. The question sought a pure PHP-based solution for POST parameter transfer during redirection.

The answer revealed that it is possible to header redirect a POST request, including its parameters. This is achieved by explicitly setting the HTTP status code to 307 before the redirect location.

header('HTTP/1.1 307 Temporary Redirect');
header('Location: anotherpage.php');

However, it's crucial to note that, according to the HTTP specification, the user agent should prompt the user for confirmation before resubmitting the POST information to the new URL. In practice, while some browsers may skip this step, Firefox presents a confirmation popup. This behavior may present potential confusion for end users in certain use cases.

Release Statement This article is reprinted at: 1729516333 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3