Testing OpenSSL with file_get_contents()

This section provides a tutorial example on how to test the PHP OpenSSL module with the file_get_contents() function to run a GET request on an HTTPS server.

The fast way to test the OpenSSL module is to use the file_get_contents() function as shown in the test script, OpenSSL_HTTPS_file_get_contents.php:

<?php
# OpenSSL_HTTPS_file_get_contents.php
#- Copyright (c) 2010-2018 HerongYang.com. All Rights Reserved.
#
$script = array_shift($argv);
$url = array_shift($argv);

$html = file_get_contents($url);
echo $html;
?>

Now let's run this script to connect the yahoo login HTTPS server, which we have used in previous tutorials with Internet Explorer and Firefox Web browsers.

herong> \local\php\php OpenSSL_HTTPS_file_get_contents.php \
   https://login.yahoo.com

<!DOCTYPE html>
<html class="no-js">
<head>
    <title>Yahoo login</title>
    <meta http-equav="Content-Type" content="text/html;charset=utf-8">
    <meta name="referrer" content="origin">
...

The test script is working! The OpenSSL module quietly helped the file_get_contents() function and performed a GET request to the HTTPS server.

Table of Contents

 About This Book

 Introduction of PKI (Public Key Infrastructure)

 Introduction of HTTPS (Hypertext Transfer Protocol Secure)

 Using HTTPS with Google Chrome

 Using HTTPS with Mozilla Firefox

 HTTPS with Microsoft Edge

 Using HTTPS with Apple Safari

 HTTPS with IE (Internet Explorer)

 Android and Server Certificate

 iPhone and Server Certificate

 Windows Certificate Stores and Console

 RDP (Remote Desktop Protocol) and Server Certificate

 macOS Certificate Stores and Keychain Access

 Perl Scripts Communicating with HTTPS Servers

PHP Scripts Communicating with HTTPS Servers

 Configuring PHP OpenSSL on Windows

Testing OpenSSL with file_get_contents()

 OpenSSL Configuration Errors

 SSL Context Options for OpenSSL

 Asking OpenSSL to Verify Server's Certificate

 OpenSSL Failing to Verify Server's Certificate

 Multiple CA Certificates in a Single File

 Testing OpenSSL with fopen()

 Testing OpenSSL with fsockopen()

 Adding CA Certificates for the PHP Engine

 Testing OpenSSL with stream_socket_client()

 Java Programs Communicating with HTTPS Servers

 .NET Programs Communicating with HTTPS Servers

 CAcert.org - Root CA Offering Free Certificates

 PKI CA Administration - Issuing Certificates

 Comodo Free Personal Certificate

 Digital Signature - Microsoft Word

 Digital Signature - OpenOffice.org 3

 S/MIME and Email Security

 PKI (Public Key Infrastructure) Terminology

 Archived Tutorials

 References

 Full Version in PDF/EPUB