§ 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.
<?php
$post_data='a=b&c=d';
PostToHost('localhost','/php_post/post_receive.php',$post_data);
function add_to_newsletter($name,$email) {
$news_name=htmlspecialchars(stripslashes($name));
$news_email=htmlspecialchars(stripslashes($email));
$post_data='u_name='.$news_name.'&u_email='.$news_email.'&r[group_id][]=1';
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);
fclose($fp);
}
?>
last edited on January 29th, 2009 at 12:30 PM
Categories
Comments
- Walid on "Adventures with Ubuntu 9.10 on G4 Yikes!" - I am in the same process as you. Although I still dual-boot to Windows for my ganimg leisure. My first contact with Ubuntu was way…
- Slashback on "Simpler adding & removing element classnames" - Actually, the addClassName function does what you want, pretty much the same way you suggest.
- angie on "Simpler adding & removing element classnames" - And what if I want to add a class, but keeping the csseals the element already has?I mean, I have an element with a class, let's name…
- backlinks on "Adjust iframe height to contents" - Definitely helped me.
- Slashback on "Simpler validate form fields are filled in (no additional class names)" - You are welcome!