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) 2011, 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.

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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3....
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Sign in to Yahoo!</title>

<meta http-equiv="Pragma" content="no-cache">
...

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

Last update: 2011.

Table of Contents

 About This Book

 Introduction of PKI (Public Key Infrastructure)

 Introduction of HTTPS (Hypertext Transfer Protocol Secure)

 Using HTTPS with IE (Internet Explorer) 10

 Using HTTPS with Chrome 40

 Using HTTPS with Firefox 35

 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()

 Java Programs Communicating with HTTPS Servers

 Certificate Stores and Certificate Console

 .NET Programs Communicating with HTTPS Servers

 CAcert.org - Root CA Offering Free Certificates

 PKI CA Administration - Issuing Certificates

 Digital Signature - Microsoft Word 2007

 Digital Signature - OpenOffice.org 3

 S/MIME and Email Security

 PKI (Public Key Infrastructure) Terminology

 Outdated Tutorials

 References

 PDF Printing Version