note 34887 modified in function.fsockopen by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 19:51:55 +0000 |
| Subject: | note 34887 modified in function.fsockopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142318@lists.php.net to get a copy of this message | ||
just a quick note for users attempting https and thinking they must resort to curl or alternate
methods -
you can use fsockopen, just read the docs closely. basically they are saying to use
'ssl://' for a HTTPS (SSL) web request.
so this would work for authorize.net, and others; even for that paypal IPN - however I think it
would be best to leave the site and deal with paypal's form:
<?php
$host = "somehost.somedomain.com";
$port = 443;
$path = "/the/url/path/file.php"; //or .dll, etc. for authnet, etc.
//you will need to setup an array of fields to post with
//then create the post string
$formdata = array ( "x_field" => "somevalue");
//build the post string
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout = 30);
if(!$fp){
//error tell us
echo "$errstr ($errno)\n";
}else{
//send the server request
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");
//loop through the response from the server
while(!feof($fp)) {
echo fgets($fp, 4096);
}
//close fp - we are done with it
fclose($fp);
}
?>
--was--
just a quick note for users attempting https and thinking they must resort to curl or alternate
methods -
you can use fsockopen, just read the docs closely. basically they are saying to use
'ssl://' for a HTTPS (SSL) web request.
so this would work for authorize.net, and others; even for that paypal IPN - however I think it
would be best to leave the site and deal with paypal's form:
$host = "somehost.somedomain.com";
$port = 443;
$path = "/the/url/path/file.php"; //or .dll, etc. for authnet, etc.
//you will need to setup an array of fields to post with
//then create the post string
$formdata = array ( "x_field" => "somevalue");
//build the post string
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout = 30);
if(!$fp){
//error tell us
echo "$errstr ($errno)\n";
}else{
//send the server request
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring . "\r\n\r\n");
//loop through the response from the server
while(!feof($fp)) {
echo fgets($fp, 4096);
}
//close fp - we are done with it
fclose($fp);
}
http://php.net/manual/en/function.fsockopen.php