Skip to content

Instantly share code, notes, and snippets.

@olivierbellone
Created July 28, 2016 09:58
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save olivierbellone/5fbe074004059c1be5cc81408b72c7b3 to your computer and use it in GitHub Desktop.
Save olivierbellone/5fbe074004059c1be5cc81408b72c7b3 to your computer and use it in GitHub Desktop.
Simple TLS version test for PHP, using howsmyssl.com
<?php
$ch = curl_init('https://www.howsmyssl.com/a/check');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$json = json_decode($data);
echo "<pre>TLS version: " . $json->tls_version . "</pre>\n";
?>
@MircoBabin
Copy link

Update to also check the stream wrapper and to show more info:

<?php

//**********************************************************
//**********************************************************
//***
//*** Curl
//***
//**********************************************************
//**********************************************************
echo "<h1>CURL</h1>";
$ch = curl_init('https://www.howsmyssl.com/a/check'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
$data = curl_exec($ch); 
curl_close($ch); 
$json = json_decode($data); 

echo "<pre>TLS version: " . $json->tls_version . "</pre>\n";
echo "<pre>" . print_r($json,true) . "</pre>\n";

//**********************************************************
//**********************************************************
//***
//*** Stream wrapper
//***
//**********************************************************
//**********************************************************
echo "<h1>Stream wrapper</h1>";
$ctx = stream_context_create(['ssl' => [
    'capture_session_meta' => TRUE
]]);
$data = file_get_contents('https://www.howsmyssl.com/a/check', FALSE, $ctx);
$json = json_decode($data); 
$meta = stream_context_get_options($ctx)['ssl']['session_meta'];

echo "<pre>TLS version: " . $json->tls_version . "</pre>\n";
echo "<pre>" . print_r($json,true) . "</pre>\n";
echo "<pre>Stream meta data\n" . print_r($meta,true) . "</pre>\n";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment