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:
<code class="php">header('Location: http://www.provider.com/process.jsp?id=12345&name=John');</code>
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.
The above is the detailed content of How to Redirect a Webpage and Send POST Data with PHP without Using HTML Forms?. For more information, please follow other related articles on the PHP Chinese website!