note 57275 added to function.fsockopen

From: Date: Thu, 29 Sep 2005 07:52:29 +0000
Subject: note 57275 added to function.fsockopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-95956@lists.php.net to get a copy of this message
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); ?> ---- Manual Page -- http://www.php.net/manual/en/function.fsockopen.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57275 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57275&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57275&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57275&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57275&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57275&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57275&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57275&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57275&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95956) next »