Sample code for 30+ languages & platforms
PHP

Use HTTPS Client Certificate from .cer and .key Files

See more HTTP Examples

Demonstrates how to load a cert + private key from .cer and .key (base64) files and use it for mutual TLS authentication (client-side certificate).

Chilkat PHP Downloads

Chilkat2 PHP
<?php

use Chilkat2\BinData;
use Chilkat2\Cert;
use Chilkat2\Http;
use Chilkat2\PrivateKey;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

$http = new Http();

$cert = new Cert();
$privKey = new PrivateKey();

// Load any type of certificate (.cer, .p7b, .pem, etc.) by calling LoadFromFile.
try {
    $cert->LoadFromFile('qa_data/certs/sample_cert_a.cer');

    // Load the private key.
    $bd = new BinData();
    $bd->LoadFile('qa_data/certs/sample_key_a.key');
    $privKey->LoadAnyFormat($bd, 'privateKeyPasswordIfNecessary');

    // Associate the private key with the cert.
    $cert->SetPrivateKey($privKey);

    // Set the certificate to be used for mutual TLS authentication
    // (i.e. sets the client-side certificate for two-way TLS authentication)
    $http->SetSslClientCert($cert);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// At this point, the HTTP object instance is setup with the client-side cert, and any SSL/TLS
// connection will automatically use it if the server demands a client-side cert.