Decode gzipped web page retrieved via cURL in PHP

The following command enables cURL’s “auto encoding” mode, where it will announce to the server which encoding methods it supports (via the Accept-Encoding header), and then automatically decompress the response for you:

// Allow cURL to use gzip compression, or any other supported encoding
// A blank string activates 'auto' mode
curl_setopt($ch, CURLOPT_ENCODING , '');

If you specifically want to force the header to be Accept-Encoding: gzip you can use this command instead:

// Allow cURL to use gzip compression, or any other supported encoding
curl_setopt($ch, CURLOPT_ENCODING , 'gzip');

Read more in the PHP documentation: curl_setopt.

Thanks to commenters for helping improve this answer.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)