Sample code for 30+ languages & platforms
PHP

Import a Certificate (.cer file) into a Windows Certificate Store

See more Certificates Examples

Demonstrates how to import a certificate (without private key) into a Windows certificate store.

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\Cert;
use Chilkat2\CertStore;

$cert = new Cert();

try {
    $cert->LoadFromFile('qa_data/certs/example.cer');
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

$certStoreCU = new CertStore();
$readOnlyFlag = false;

// "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
try {
    $certStoreCU->OpenWindowsStore('CurrentUser', 'My', $readOnlyFlag);
} catch (\Chilkat2\Exception $e) {
    echo "Failed to open the CurrentUser/My certificate store for read/write.\n";
    exit;
}

// Import the certificate into the CurrentUser/My certificate store.
try {
    $certStoreCU->AddCertificate($cert);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

echo 'Imported ', $cert->SubjectCN, "\n";
echo "Success.\n";