Skip to content

How to Force Use TLS 1.2 with cURL PHP

Category
PHP
Covers
curl, SSL/TLS
Versions & support
About PHP →
On this page

Most of the Web/API services providers are shifting their environments to TLS 1.2 or greater. So to consume their services via PHP applications, you also need to force your application to use TLS 1.2 during making a connection. This tutorial will help you, how to use TLS 1.2 with PHP cURL.

Using TLS 1.2 with PHP CURL Forcefully

You can add the following code to your curl requests to use TLS 1.2. Use 6 as the value of CURLOPT_SSLVERSION forces cURL to use TLS 1.2.

Below is the sample code to force use tls 1.2 with php curl:

For the example, I am using a sample script from our another articlesubmitting JSON data with cURL and PHP. In that script, we will add code to forece use of tls 1.2.

Below is the sample script:

You can execute above script in webbrowser or from the command line interface.

Conclusion

In this tutorial, you have learned to use tls 1.2 with PHP/cURL forcefully.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top