34 function getURLContent($url,$postorget=
'GET',$param=
'',$followlocation=1,$addheaders=array())
38 $USE_PROXY=empty($conf->global->MAIN_PROXY_USE)?0:$conf->global->MAIN_PROXY_USE;
39 $PROXY_HOST=empty($conf->global->MAIN_PROXY_HOST)?0:$conf->global->MAIN_PROXY_HOST;
40 $PROXY_PORT=empty($conf->global->MAIN_PROXY_PORT)?0:$conf->global->MAIN_PROXY_PORT;
41 $PROXY_USER=empty($conf->global->MAIN_PROXY_USER)?0:$conf->global->MAIN_PROXY_USER;
42 $PROXY_PASS=empty($conf->global->MAIN_PROXY_PASS)?0:$conf->global->MAIN_PROXY_PASS;
44 dol_syslog(
"getURLContent postorget=".$postorget.
" URL=".$url.
" param=".$param);
53 curl_setopt($ch, CURLOPT_URL, $url);
54 curl_setopt($ch, CURLOPT_VERBOSE, 1);
55 curl_setopt($ch, CURLOPT_USERAGENT,
'Dolibarr geturl function');
57 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, ($followlocation?
true:
false));
59 if (count($addheaders)) curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders);
60 curl_setopt($ch, CURLINFO_HEADER_OUT,
true);
64 if (! empty($conf->global->MAIN_CURL_SSLVERSION)) curl_setopt($ch, CURLOPT_SSLVERSION, $conf->global->MAIN_CURL_SSLVERSION);
68 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,
false);
69 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,
false);
71 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, empty($conf->global->MAIN_USE_CONNECT_TIMEOUT)?5:$conf->global->MAIN_USE_CONNECT_TIMEOUT);
72 curl_setopt($ch, CURLOPT_TIMEOUT, empty($conf->global->MAIN_USE_RESPONSE_TIMEOUT)?30:$conf->global->MAIN_USE_RESPONSE_TIMEOUT);
75 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
76 if ($postorget ==
'POST')
78 curl_setopt($ch, CURLOPT_POST, 1);
79 curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
81 else if ($postorget ==
'PUT')
83 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'PUT');
84 if (! is_array($param)) parse_str($param, $array_param);
87 dol_syslog(
"parameter param must be a string", LOG_WARNING);
90 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param));
92 else if ($postorget ==
'PUTALREADYFORMATED')
94 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'PUT');
95 curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
97 else if ($postorget ==
'HEAD')
99 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'HEAD');
100 curl_setopt($ch, CURLOPT_NOBODY,
true);
102 else if ($postorget ==
'DELETE')
104 curl_setopt($ch, CURLOPT_CUSTOMREQUEST,
'DELETE');
108 curl_setopt($ch, CURLOPT_POST, 0);
114 dol_syslog(
"getURLContent set proxy to ".$PROXY_HOST.
":" . $PROXY_PORT.
" - ".$PROXY_USER.
":" . $PROXY_PASS);
116 curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.
":" . $PROXY_PORT);
117 if ($PROXY_USER) curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.
":" . $PROXY_PASS);
121 $response = curl_exec($ch);
123 $request = curl_getinfo($ch, CURLINFO_HEADER_OUT);
125 dol_syslog(
"getURLContent request=".$request);
127 dol_syslog(
"getURLContent response size=".strlen($response));
133 $rep[
'content']=$response;
136 $rep[
'curl_error_no']=curl_errno($ch);
137 $rep[
'curl_error_msg']=curl_error($ch);
139 dol_syslog(
"getURLContent response array is ".join(
',',$rep));
143 $info = curl_getinfo($ch);
149 dol_syslog(
"getURLContent http_code=".$rep[
'http_code']);
152 $rep[
'content']=$response;
153 $rep[
'curl_error_no']=
'';
154 $rep[
'curl_error_msg']=
'';
173 $tmpdomain = preg_replace(
'/^https?:\/\//i',
'', $url);
174 $tmpdomain = preg_replace(
'/\/.*$/i',
'', $tmpdomain);
175 $tmpdomain = preg_replace(
'/\.[^\.]+$/',
'', $tmpdomain);
176 $tmpdomain = preg_replace(
'/^[^\.]+\./',
'', $tmpdomain);
193 if (preg_match(
'/^(https?:\/\/)/i', $tmpurl, $reg)) $prefix = $reg[1];
194 $tmpurl = preg_replace(
'/^https?:\/\//i',
'', $tmpurl);
195 $tmpurl = preg_replace(
'/\/.*$/i',
'', $tmpurl);
197 return $prefix.$tmpurl;
208 $content = preg_replace(
'/<!--[^\-]+-->/',
'', $content);
removeHtmlComment($content)
Function to remove comments into HTML content.
getDomainFromURL($url)
Function get second level domain name.
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page.html return 'https://www.abc.mydomain.com' For example: http://www.abc.mydomain.com/ return 'https://www.abc.mydomain.com'.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array())
Function get content from an URL (use proxy if proxy defined)