Sample code for 30+ languages & platforms
PHP

Find Certificate by Serial Number

See more Cert Store Examples

Demonstrates how to find a certificate having the specified hexadecimal serial number.

Note: Requires Chilkat v10.1.2 or later.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Cert;
use Chilkat2\CertStore;
use Chilkat2\JsonObject;

$certStore = new CertStore();

// This example will search the certs on connected USB tokens and smartcards.
$argNotUsed = '';
try {
    $certStore->OpenSmartcard($argNotUsed);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Find the certificate having a serial number = "48FC93B46055948D36A7C98A89D69416".
$hexSerial = '48FC93B46055948D36A7C98A89D69416';
$json = new JsonObject();
$json->UpdateString('serial', $hexSerial);

$cert = new Cert();
try {
    $certStore->FindCert($json, $cert);
    // Show the serial number and subject CN
    echo 'Found: ', $cert->SerialNumber, ', ', $cert->SubjectCN, "\n";
} catch (\Chilkat2\Exception $e) {
    echo "Not found.\n";
}