PHP script to test HTTPS secure connection through proxy server

The following PHP can be used to test if a web server can make a https connection through a proxy server.

This can be useful if you need to test if a web server is capable of making secure connections to a payment gateway or similar secure service.

To use, place the script in a PHP file, replace the proxyaddress with your proxy server details and run the script.

If it works you will see the URL you requested (in this case the Facebook home page), if it doesn’t you should see a useful error message.

 

<?php 
$url = 'https://www.facebook.com/'; // the url to test a POST request to 
$data = array( 'key1' => 'value1', 'key2' => 'value2' ); // any data to send in the request

// use key 'http' even if you send the request to https://...
$options = array(
    'http' => array(
		'proxy' => 'tcp://proxyaddress:8080',
		'request_fulluri' => true,
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query( $data )
    )
);

error_reporting( ~0 );
ini_set( 'display_errors', 1 );

$context = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );

var_dump( $result );