Last active
March 11, 2016 12:43
-
-
Save dkrusky/1202211b1de37a166eaa to your computer and use it in GitHub Desktop.
Get SSL/TLS certificate details and full headers from a secure website.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$details = getRawSecureWebsite('www.google.com'); | |
echo '<textarea>' . $details['raw'] . '</details>'; | |
function getRawSecureWebsite( $domain ) { | |
$raw = ''; | |
$headers = ''; | |
$error = ''; | |
if($stderr = tmpfile()) { | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL,"https://" . $domain); | |
curl_setopt($ch, CURLOPT_STDERR, $stderr); | |
curl_setopt($ch, CURLOPT_CERTINFO, 1); | |
curl_setopt($ch, CURLOPT_VERBOSE, 1); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
curl_setopt($ch, CURLOPT_NOBODY, 1); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); | |
curl_setopt($ch, CURLOPT_RETURN_TRANSFER, true); | |
$headers = curl_exec($ch); | |
if(curl_errno($ch)==0) { | |
fseek($stderr, 0); | |
while(!feof($stderr)) { | |
$raw .= fread($stderr, 8192); | |
} | |
fclose($stderr); | |
} else { | |
$error = curl_errno($ch) . ' ' . curl_error($ch); | |
} | |
curl_close($ch); | |
} | |
return Array( | |
'raw' => $raw, | |
'headers' => $headers, | |
'error' => $error | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment