PHP Curl Request with Certificate (cert pem file option) Example

By Hardik Savani November 5, 2023 Category : PHP


This tutorial shows you php curl request with certificate. if you have question about php curl request with pem certificate then i will give simple example with solution. Here you will learn php curl request pass pem file. you will learn how to send a curl request with pem certificate in php. follow bellow step for php send curl request with pem file certificate.

In this example i will give you example of how to send curl request with pem file certificate authentication request. you can pass pem file certificate as like bellow:

curl_setopt($ch, CURLOPT_SSLCERT, "mycert.pem");

curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");



$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, '');

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_POST, 1);

curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_cert");

curl_setopt($ch, CURLOPT_SSLCERT, "mycert.pem");

curl_setopt($ch, CURLOPT_SSLCERTTYPE, "PEM");

$headers = [];

$headers[] = 'Content-Type: application/x-www-form-urlencoded';

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);

if (curl_errno($ch)) {

return false;



$result = json_decode($result);



i hope it can help you...

Tags :