Skip to content

How to Force Use TLS 1.2 with cURL PHP

Advertisement

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

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply

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


Back to top