Useful notes & manuals
from the
world wide web
L:
P:
Register now!
Submit a form using POST method through PHP PHP
Solution from: unknown Created on 16.01.2025 @ 07:39

To submit a form using POST method through PHP, just add the data to be posted as header. This essentially saves one extra html page sent to the browser when user has to be redirected. Mostly found this technique useful for redirecting to payment gateways. 

<?php
$host = "www.example.com";
$path = "/path/to/script.php";
$data = "data1=value1&data2=value2";
$data = urlencode($data);


header("POST $path HTTP/1.1rn" );
header("Host: $hostrn" );
header("Content-type: application/x-www-form-urlencodedrn" );
header("Content-length: " . strlen($data) . "rn" );
header("Connection: closernrn" );
header($data);
?> 

submit   form   method   post   payment   gateway   redirect   header
 
Created by THE LOST WEB © 2009-2012