Sample code for 30+ languages & platforms
PHP Extension

Iterate over Certificates in a Certificate Store

See more Cert Store Examples

Demonstrates how to iterate over the certificates in a certificate store.

Note: Requires Chilkat v10.1.2 or later.

Chilkat PHP Extension Downloads

PHP Extension
<?php

include("chilkat.php");

$success = false;

$certStore = new CkCertStore();

// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
$readOnly = false;
$success = $certStore->OpenCurrentUserStore($readOnly);
if ($success == false) {
    print $certStore->lastErrorText() . "\n";
    exit;
}

$cert = new CkCert();

$numCerts = $certStore->get_NumCertificates();
$i = 0;

while (($i < $numCerts)) {
    // Load the cert object with the Nth certificate.
    $certStore->GetCert($i,$cert);
    print $i . ': ' . $cert->subjectCN() . "\n";
    $i = $i + 1;
}


?>