note 57275 deleted from function.fsockopen by danbrown

From: Date: Mon, 18 May 2009 01:54:47 +0000
Subject: note 57275 deleted from function.fsockopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155609@lists.php.net to get a copy of this message
Note Submitter: alex at renesource dot lv ---- Setting up SSL connection to server that requires client certificate (https). Function fsockopen() has 5 arguments only in PHP5. There is sixth undocumented argument in PHP4 fsockopen() function . Therefore code in note 'alex at renesource dot lv 16-Mar-2004 09:07' will work with PHP4 only. You can use the following code to post request to HTTPS server that requires client certificate to establish SSL connection: <?php # working vars $host = 'ssl.host.com'; $service_uri = '/some/service/address'; $local_cert_path = '/path/to/keys.pem'; $local_cert_passphrase = 'pass_to_access_keys'; $request_data = '<some><xml>data</xml></some>'; # array with the options to create stream context $opts = Array(); # compose HTTP request header $header = "Host: $host\\r\\n"; $header .= "User-Agent: PHP Script\\r\\n"; $header .= "Content-Type: text/xml\\r\\n"; $header .= "Content-Length: ".strlen($request_data)."\\r\\n"; $header .= "Connection: close"; # define context options for HTTP request (use 'http' index, NOT 'httpS') $opts['http']['method'] = 'POST'; $opts['http']['header'] = $header; $opts['http']['content'] = $request_data; # define context options for SSL transport $opts['ssl']['local_cert'] = $local_cert_path; $opts['ssl']['passphrase'] = $local_cert_passphrase; # create stream context $context = stream_context_create($opts); # POST request and get response $filename = 'https://'.$host.$service_uri; $content = file($filename, false, $context); $response_data = implode('', $content); ?>

« previous php.notes (#155609) next »