Home  >  Article  >  Backend Development  >  How to Redirect a Webpage and Send POST Data with PHP without Using HTML Forms?

How to Redirect a Webpage and Send POST Data with PHP without Using HTML Forms?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-26 23:35:30308browse

How to Redirect a Webpage and Send POST Data with PHP without Using HTML Forms?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn