« Blog Home

§ Send POST request from PHP

A way to send a POST request from PHP.

The PostToHost function does the work.  The code above it shows examples of how to call it.




function add_to_newsletter($name,$email) {


  PostToHost('localhost', '/mailing/subscribe/enter.php', $post_data);

function PostToHost($host, $path, $data_to_send) {
  $eol = "rn";
  $fp = fsockopen($host,80);
  fputs($fp, "POST $path HTTP/1.1".$eol );
  fputs($fp, "Host: $host".$eol );
  fputs($fp, "Content-type: application/x-www-form-urlencoded".$eol );
  fputs($fp, "Content-length: ".strlen($data_to_send).$eol );
  fputs($fp, "Connection: close".$eol.$eol );
  fputs($fp, $data_to_send);



last edited on January 29th, 2009 at 12:30 PM


No Comments Here. Add yours below!

Add your comment

Email: (Will not be displayed - Privacy policy)
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)

« Blog Home

The abbot shook his head.  “Michael and the others went too far when they went to the Kaiser.  It is not for us to order the affairs of kings, but to care for the poor and lowly.”
“That,” said Dietrich, “may require you to order the affairs of kings.”
an abbot & Dietrich, Eifelheim, Michael Flynn