PHP Extension
PHP Extension
Get the Server Certificate, Certificate Chain, and Root CA Certificate
See more HTTP Examples
Demonstrates how to get the HTTP server certificate, its certificate chain, and the root CA certificate.Chilkat PHP Extension Downloads
<?php
include("chilkat.php");
$success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$http = new CkHttp();
// We're getting the SSL/TLS certificate, so make sure to connect to the SSL/TLS port (443).
$sslCert = new CkCert();
$success = $http->GetServerCert('apple.com',443,$sslCert);
if ($success == false) {
print $http->lastErrorText() . "\n";
exit;
}
$certChain = new CkCertChain();
$success = $sslCert->BuildCertChain($certChain);
if ($success == false) {
print $sslCert->lastErrorText() . "\n";
exit;
}
$cert = new CkCert();
$i = 0;
$numCerts = $certChain->get_NumCerts();
while ($i < $numCerts) {
$certChain->CertAt($i,$cert);
print 'SubjectDN ' . $i . ': ' . $cert->subjectDN() . "\n";
print 'IssuerDN ' . $i . ': ' . $cert->issuerDN() . "\n";
$i = $i + 1;
}
// If the certificate chain reaches the root CA cert, then the last cert in the chain
// is the root CA cert.
if ($certChain->get_ReachesRoot() == true) {
$caCert = new CkCert();
$certChain->CertAt($numCerts - 1,$caCert);
print 'CA Root Cert: ' . $caCert->subjectDN() . "\n";
}
?>