How-to articles, tricks, and solutions about CURL

Call to undefined function curl_init() even it is enabled in php7

The error message "Call to undefined function curl_init()" typically indicates that the cURL extension for PHP is not installed or is not enabled.

Can't connect to HTTPS site using cURL. Returns 0 length content instead. What can I do?

There are several possible reasons why cURL is returning a 0 length response when trying to connect to an HTTPS site.

Compiling php with curl, where is curl installed?

The location of the curl installation depends on the operating system and the method used to install it.

CURL and HTTPS, "Cannot resolve host"

It sounds like you are trying to use curl to make a request to an HTTPS url and are encountering an error that says "Cannot resolve host." This error can occur for a few reasons:

Curl and PHP - how can I pass a json through curl by PUT,POST,GET

To pass a JSON object through cURL using the PUT method, you can use the following command:

curl error 18 - transfer closed with outstanding read data remaining

Error 18 means that the transfer was closed with outstanding read data remaining.

Curl error 60, SSL certificate issue: self signed certificate in certificate chain

This error message appears when curl is unable to verify the SSL/TLS certificate presented by the server.

CURL ERROR: Recv failure: Connection reset by peer - PHP Curl

This error is usually caused by a network issue, such as a lost connection or a network timeout.

curl POST format for CURLOPT_POSTFIELDS

To make a POST request with PHP's cURL functions, you can use the CURLOPT_POST option to send POST data.

curl posting with header application/x-www-form-urlencoded

To make a POST request using curl and include a header of Content-Type: application/x-www-form-urlencoded, you can use the following command:

Downloading a large file using curl

To download a large file using curl, use the following command:

Getting title and meta tags from external website

In PHP, you can use the file_get_contents() function to retrieve the HTML code of a website, and then use regular expressions or a DOM parsing library to extract the title and meta tags.

How do I get a YouTube video thumbnail from the YouTube API?

To get a thumbnail image for a YouTube video in PHP, you can use the file_get_contentsfunction to make a GET request to the videos.list method of the YouTube Data API.

How to enable cURL in PHP / XAMPP

To enable cURL in PHP, you need to make sure that the cURL extension is enabled in your PHP configuration.

How to get file_get_contents() to work with HTTPS?

To get file_get_contents() to work with HTTPS, you may need to make sure that PHP has been compiled with the OpenSSL extension.

How to get info on sent PHP curl request

To get information about a cURL request that you have sent using PHP, you can use the curl_getinfo() function.

How to get page content using cURL?

To get the content of a webpage using cURL, you can use the following command:

How to include Authorization header in cURL POST HTTP Request in PHP?

To include the Authorization header in a cURL POST request in PHP, you can use the CURLOPT_HTTPHEADER option and pass it an array of headers like this:

How to Send a Post Request with PHP

In this snippet, we will share with you the most flexible and powerful ways of sending post requests with the help of PHP. Just check out the examples.

how to upload file using curl with PHP

To upload a file using cURL in PHP, you can use the curl_setopt function to specify the CURLOPT_POSTFIELDS option with the file data.

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The error message "JSONDecodeError: Expecting value: line 1 column 1 (char 0)" typically occurs when you are trying to parse a string as JSON, but the string is not in a valid JSON format.

PHP CURL DELETE request

To send a DELETE request with PHP using cURL, you can use the following code:

PHP cURL how to add the User Agent value OR overcome the Servers blocking cURL requests?

You can add a custom User Agent value to a cURL request in PHP using the CURLOPT_USERAGENT option.

PHP cURL HTTP CODE return 0

If cURL is returning a HTTP code of 0, it usually indicates that cURL was unable to communicate with the server.

PHP cURL HTTP PUT

To make an HTTP PUT request using PHP's cURL functions, you can use the following snippet:

1 2