From bc28c5da8e93ad38bc54726abea51462522f6158 Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sun, 25 Mar 2018 15:48:30 +0200 Subject: [PATCH] [contents] Set CURLOPT_HTTPHEADER only if the provided array contains data --- lib/contents.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/contents.php b/lib/contents.php index 7fbda2d..591e38e 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -3,7 +3,10 @@ function getContents($url, $header = array(), $opts = array()){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + + if(is_array($header) && count($header) !== 0) + curl_setopt($ch, CURLOPT_HTTPHEADER, $header); + curl_setopt($ch, CURLOPT_USERAGENT, ini_get('user_agent')); curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);