note 34887 added to function.fsockopen

From: Date: Sun, 10 Aug 2003 07:56:01 +0000
Subject: note 34887 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-53805@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: $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 .= $key . "=" . urlencode($val) . "&"; } $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\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: application/x-www-form-urlencoded\n"); fputs($fp, "Content-length: ".strlen($poststring)."\n"); fputs($fp, "Connection: close\n\n"); fputs($fp, $poststring); //loop through the response from the server while(!feof($fp)) { echo fgets($fp, 4096); } //close fp - we are done with it fclose($fp); } ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34887 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34887&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34887&report=yes

« previous php.notes (#53805) next »