Redirecting and Sending POST Data with PHP
In this question, we encounter a unique challenge: how to redirect a webpage and send data via the POST method without relying on HTML forms. The desired outcome is to submit hidden fields to an external gateway using a PHP script. Typically, sending data via GET is straightforward, as exemplified by the code snippet below:
header('Location: http://www.provider.com/process.jsp?id=12345&name=John');
However, sending data via POST using solely PHP is not possible. As mentioned in the accepted answer, cURL can be employed to achieve this, but it requires the PHP code to act as the browser client rather than a server-side script.
An alternative solution, albeit more complex, involves creating a populated form dynamically using PHP and employing JavaScript to submit it. This approach is outlined in the provided answer and allows for POST data transmission without HTML forms.
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