ItSolutionStuff.com

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

By Hardik Savani • May 14, 2024
PHP

Hi,

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");

Example:

<?php

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://example.com/token');

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;

}

curl_close($ch);

$result = json_decode($result);

print_r($result);

?>

i hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular Material Autocomplete with API Example

Read Now →

Laravel Sanctum SPA API Authentication Example

Read Now →

Laravel 8 Sanctum API Authentication Tutorial

Read Now →

Laravel 8 REST API with Passport Authentication Tutorial

Read Now →

Codeigniter Curl Post Request with Parameters Example

Read Now →

PHP CURL Post Request with Parameters Example

Read Now →

Laravel Block/Whitelist IP Address Tutorial

Read Now →

Laravel CURL Request Example using Ixudra/curl

Read Now →

Laravel Mailchimp API Integration Example

Read Now →

PHP Download File from URL using CURL Request Example

Read Now →

How to Get Product using Rakuten Marketing API in PHP?

Read Now →