ItSolutionStuff.com

PHP Curl Request with P12 Certificate Example

By Hardik Savani β€’ May 14, 2024
PHP

Today our leading topic is php curl request with p12 certificate. we will help you to give example of php curl request with p12 certificate. This article goes in detailed on php curl request pass p12 file. we will help you to give example of how to send a curl request with p12 certificate in php. Alright, let’s dive into the steps.

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

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

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

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

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

$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...

Tags: PHP
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

β˜…

Laravel Http Curl Delete Request Example

Read Now β†’
β˜…

Laravel Http Curl Get Request Example

Read Now β†’
β˜…

PHP Curl Request with Username and Password Example

Read Now β†’
β˜…

PHP Curl Request With Bearer Token Authorization Header Example

Read Now β†’
β˜…

PHP Curl PUT Request Example Code

Read Now β†’
β˜…

PHP Curl Delete Request Example Code

Read Now β†’
β˜…

PHP Curl POST Request with Headers Example

Read Now β†’
β˜…

PHP Curl Get Request with Parameters Example

Read Now β†’
β˜…

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

Read Now β†’
β˜…

Codeigniter Curl Post Request with Parameters Example

Read Now β†’
β˜…

PHP CURL Post Request with Parameters Example

Read Now β†’