Sample code for 30+ languages & platforms
PHP

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 Downloads

Chilkat2 PHP
<?php

use Chilkat2\Cert;
use Chilkat2\CertStore;

$certStore = new CertStore();

// This opens the Current User certificate store on Windows,
// On MacOS and iOS it opens the default Keychain.
$readOnly = false;
try {
    $certStore->OpenCurrentUserStore($readOnly);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$cert = new Cert();

$numCerts = $certStore->NumCertificates;
$i = 0;

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