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.

Advertisement

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.

Share.
Leave A Reply


Exit mobile version