How to perform certificate-based authentication using PHP HTTP client

I need to access the RESTful web service from PHP (GET only). Access to the service is only possible through HTTPS with a valid client certificate.

I found many basic examples for PHP for PHP, but not one for the client-side HTTP authentication protocol on the client side. Is there a PHP HTTP client that can also send certificates to the server?

I am currently using an external application (wget), but it is rather slow and hacky.

+3
source share
1 answer

Certificate-based authentication is not part of HTTP, but is part of the SSL / TLS protocol.

cURL :

$ch = curl_init('https://example.com/');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
curl_setopt($ch, CURLOPT_CAINFO, '/path/to/cert/ca.crt');
curl_setopt($ch, CURLOPT_SSLCERT, '/path/to/cert/client-cert.pem');
$response = curl_exec();
curl_close($ch);

. curl_setopt.

+6

All Articles