dolibarr 23.0.3
geturl.lib.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008-2020 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 * or see https://www.gnu.org/
19 */
20
48function getURLContent($url, $postorget = 'GET', $param = '', $followlocation = 1, $addheaders = array(), $allowedschemes = array('http', 'https'), $localurl = 0, $ssl_verifypeer = -1, $timeoutconnect = 0, $timeoutresponse = 0, $otherCurlOptions = array())
49{
50 // Get global variables for proxy use
51 $USE_PROXY = getDolGlobalInt('MAIN_PROXY_USE');
52 $PROXY_HOST = getDolGlobalString('MAIN_PROXY_HOST');
53 $PROXY_PORT = getDolGlobalInt('MAIN_PROXY_PORT');
54 $PROXY_USER = getDolGlobalString('MAIN_PROXY_USER');
55 $PROXY_PASS = getDolGlobalString('MAIN_PROXY_PASS');
56
57 dol_syslog("getURLContent postorget=".$postorget." URL=".$url);
58 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
59 dol_syslog("getURLContent postorget=".$postorget." URL=".$url." json_encode(param)=".json_encode($param), LOG_DEBUG, 0, '_curl');
60 }
61
62 if (!function_exists('curl_init')) {
63 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
64 dol_syslog("getURLContent PHP curl library must be installed", LOG_DEBUG, 0, '_curl');
65 }
66 return array('http_code' => 500, 'content' => '', 'curl_error_no' => 1, 'curl_error_msg' => 'PHP curl library must be installed');
67 }
68
69 //setting the curl parameters.
70 $ch = curl_init();
71
72 /*print $API_Endpoint."-".$API_version."-".$PAYPAL_API_USER."-".$PAYPAL_API_PASSWORD."-".$PAYPAL_API_SIGNATURE."<br>";
73 print $USE_PROXY."-".$gv_ApiErrorURL."<br>";
74 print $nvpStr;
75 exit;*/
76 curl_setopt($ch, CURLOPT_VERBOSE, true);
77 curl_setopt($ch, CURLOPT_USERAGENT, 'Dolibarr geturl function'); // set the Dolibarr user agent name
78
79 // We use @ here because this may return warning if safe mode is on or open_basedir is on (following location is forbidden when safe mode is on).
80 // We force value to false so we will manage redirection ourself later.
81 @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
82
83 if (is_array($addheaders) && count($addheaders)) {
84 curl_setopt($ch, CURLOPT_HTTPHEADER, $addheaders);
85 }
86 curl_setopt($ch, CURLINFO_HEADER_OUT, true); // To be able to retrieve request header and log it
87
88 if (getDolGlobalInt('MAIN_CURL_GET_RESPONSE_HEADER')) {
89 curl_setopt($ch, CURLOPT_HEADER, true); // To be able to retrieve response header
90 }
91
92 // By default use the TLS version decided by PHP.
93 // You can force, if supported a version like TLSv1 or TLSv1.2
94 if (getDolGlobalString('MAIN_CURL_SSLVERSION')) {
95 $sslversion = is_numeric(getDolGlobalString('MAIN_CURL_SSLVERSION')) ? getDolGlobalInt('MAIN_CURL_SSLVERSION') : constant(getDolGlobalString('MAIN_CURL_SSLVERSION'));
96 curl_setopt($ch, CURLOPT_SSLVERSION, (int) $sslversion);
97 }
98 //curl_setopt($ch, CURLOPT_SSLVERSION, 6); for tls 1.2
99
100 // Turning on or off the ssl target certificate
101 if ($ssl_verifypeer < 0) {
102 global $dolibarr_main_prod;
103 $ssl_verifypeer = ($dolibarr_main_prod ? true : false);
104 }
105 if (getDolGlobalString('MAIN_CURL_DISABLE_VERIFYPEER')) {
106 $ssl_verifypeer = 0;
107 }
108
109 // Turning off the server and peer verification(TrustManager Concept).
110 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, ($ssl_verifypeer ? true : false));
111
112 // 0 to not check the names
113 // 1 to check the existence of a common name in the SSL peer certificate
114 // 2 to check the existence of a common name and also verify that it matches the hostname provided.
115 // In production environments the value of this option should be kept at 2 (default value).
116 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, ($ssl_verifypeer ? 2 : 0));
117
118 // Restrict use to some protocols only
119 $protocols = 0;
120 $redir_list = array();
121 if (is_array($allowedschemes)) {
122 foreach ($allowedschemes as $allowedscheme) {
123 if ($allowedscheme == 'http') {
124 $protocols |= CURLPROTO_HTTP;
125 $redir_list["HTTP"] = 1;
126 } elseif ($allowedscheme == 'https') {
127 $protocols |= CURLPROTO_HTTPS;
128 $redir_list["HTTPS"] = 1;
129 } elseif ($allowedscheme == 'ftp') {
130 $protocols |= CURLPROTO_FTP;
131 $redir_list["FTP"] = 1;
132 } elseif ($allowedscheme == 'ftps') {
133 $protocols |= CURLPROTO_FTPS;
134 $redir_list["FTPS"] = 1;
135 }
136 }
137 }
138
139 $newtimeoutconnect = ($timeoutconnect ? $timeoutconnect : getDolGlobalInt('MAIN_USE_CONNECT_TIMEOUT', 5));
140 $newtimeoutresponse = ($timeoutresponse ? $timeoutresponse : getDolGlobalInt('MAIN_USE_RESPONSE_TIMEOUT', 30));
141
142 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
143 dol_syslog("getURLContent newtimeoutconnect=".$newtimeoutconnect." newtimeoutresponse=".$newtimeoutresponse, LOG_DEBUG, 0, '_curl');
144 }
145
146 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $newtimeoutconnect);
147 curl_setopt($ch, CURLOPT_TIMEOUT, $newtimeoutresponse);
148
149 // limit size of downloaded files.
150 $maxsize = getDolGlobalInt('MAIN_SECURITY_MAXFILESIZE_DOWNLOADED');
151 if ($maxsize && defined('CURLOPT_MAXFILESIZE_LARGE')) {
152 curl_setopt($ch, CURLOPT_MAXFILESIZE_LARGE, $maxsize * 1024); // @phan-suppress-current-line PhanTypeMismatchArgumentNullableInternal
153 }
154 if ($maxsize && defined('CURLOPT_MAXFILESIZE')) {
155 curl_setopt($ch, CURLOPT_MAXFILESIZE, $maxsize * 1024);
156 }
157
158 //curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true); // PHP 5.5
159 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // We want response
160 if ($postorget == 'POST') {
161 curl_setopt($ch, CURLOPT_POST, true); // POST
162 curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as POST fields
163 } elseif ($postorget == 'POSTALREADYFORMATED') {
164 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // HTTP request is 'POST' but param string is taken as it is
165 curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string
166 } elseif ($postorget == 'PUT') {
167 $array_param = array();
168 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
169 if (!is_array($param)) {
170 parse_str($param, $array_param);
171 } else {
172 dol_syslog("parameter param must be a string", LOG_WARNING);
173 $array_param = $param;
174 }
175 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields
176 } elseif ($postorget == 'PUTALREADYFORMATED') {
177 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT'
178 curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // param = content of post, like a xml string
179 } elseif ($postorget == 'PATCH') {
180 $array_param = array();
181 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); // RFC 5789
182 if (!is_array($param)) {
183 parse_str($param, $array_param);
184 } else {
185 dol_syslog("parameter param must be a string", LOG_WARNING);
186 $array_param = $param;
187 }
188 curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param));
189 } elseif ($postorget == 'PATCHALREADYFORMATED') {
190 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); // RFC 5789
191 curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
192 } elseif ($postorget == 'HEAD') {
193 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD'
194 curl_setopt($ch, CURLOPT_NOBODY, true);
195 } elseif ($postorget == 'DELETE') {
196 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST
197 } else {
198 curl_setopt($ch, CURLOPT_POST, false); // GET
199 }
200
201 //if USE_PROXY constant set at begin of this method.
202 if ($USE_PROXY) {
203 dol_syslog("getURLContent set proxy to ".$PROXY_HOST.":".$PROXY_PORT." - ".$PROXY_USER.":".$PROXY_PASS);
204 //curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP); // Curl 7.10
205 curl_setopt($ch, CURLOPT_PROXY, $PROXY_HOST.":".$PROXY_PORT);
206 if ($PROXY_USER) {
207 curl_setopt($ch, CURLOPT_PROXYUSERPWD, $PROXY_USER.":".$PROXY_PASS);
208 }
209 }
210
211 if (is_array($otherCurlOptions)) {
212 foreach ($otherCurlOptions as $option => $value) {
213 curl_setopt($ch, $option, $value);
214 }
215 }
216
217 $newUrl = $url;
218 $maxRedirection = 5;
219 $info = array();
220 $response = '';
221
222 do {
223 if ($maxRedirection < 1) {
224 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
225 dol_syslog("getURLContent http_code=400 Maximum number of redirections reached", LOG_DEBUG, 0, '_curl');
226 }
227 return array('http_code' => 400, 'content' => 'Maximum number of redirections reached', 'curl_error_no' => 1, 'curl_error_msg' => 'Maximum number of redirections reached');
228 }
229
230 curl_setopt($ch, CURLOPT_URL, $newUrl);
231
232 // Parse $newUrl
233 $newUrlArray = parse_url($newUrl);
234 $hosttocheck = $newUrlArray['host'];
235 $hosttocheck = str_replace(array('[', ']'), '', $hosttocheck); // Remove brackets of IPv6
236
237 // Deny some reserved host names
238 if (in_array($hosttocheck, array('metadata.google.internal'))) {
239 $info['http_code'] = 400;
240 $info['content'] = 'Error bad hostname '.$hosttocheck.' (Used by Google metadata). This value for hostname is not allowed.';
241 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
242 dol_syslog("getURLContent http_code=400 ".$info['content'], LOG_DEBUG, 0, '_curl');
243 }
244 return array('http_code' => 400, 'content' => $info['content'], 'curl_error_no' => 1, 'curl_error_msg' => $info['content']);
245 }
246
247 // Clean host name $hosttocheck to convert it into an IP $iptocheck
248 if (in_array($hosttocheck, array('localhost', 'localhost.domain'))) {
249 $iptocheck = '127.0.0.1';
250 } elseif (in_array($hosttocheck, array('ip6-localhost', 'ip6-loopback'))) {
251 $iptocheck = '::1';
252 } else {
253 // Resolve $hosttocheck to get the IP $iptocheck
254 if (function_exists('gethostbyname')) {
255 $iptocheck = gethostbyname($hosttocheck);
256 } else {
257 $iptocheck = $hosttocheck;
258 }
259 // TODO Resolve ip v6
260 }
261
262 // Check $iptocheck is an IP (v4 or v6), if not clear value.
263 if (!filter_var($iptocheck, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6)) { // This is not an IP, we clean data
264 $iptocheck = '0'; //
265 }
266
267 if ($iptocheck) {
268 $tmpresult = isIPAllowed($iptocheck, $localurl);
269 if ($tmpresult) {
270 $info['http_code'] = 400;
271 $info['content'] = $tmpresult;
272 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
273 dol_syslog("getURLContent http_code=400 ".$info['content'], LOG_DEBUG, 0, '_curl');
274 }
275 return array('http_code' => 400, 'content' => $tmpresult, 'curl_error_no' => 1, 'curl_error_msg' => $tmpresult);
276 }
277 }
278
279 if ($iptocheck) {
280 // Set CURLOPT_CONNECT_TO so curl will not try another resolution that may give a different result. Possible only on PHP v7+
281 if (defined('CURLOPT_CONNECT_TO')) {
282 $connect_to = array(sprintf("%s:%d:%s:%d", $newUrlArray['host'], empty($newUrlArray['port']) ? '' : $newUrlArray['port'], $iptocheck, empty($newUrlArray['port']) ? '' : $newUrlArray['port']));
283 //var_dump($newUrlArray);
284 //var_dump($connect_to);
285 curl_setopt($ch, CURLOPT_CONNECT_TO, $connect_to);
286 }
287 }
288
289 // Moving these just before the curl_exec option really limits
290 // on windows PHP 7.4.
291 curl_setopt($ch, CURLOPT_PROTOCOLS, $protocols);
292 curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, $protocols);
293 /* CURLOPT_REDIR_PROTOCOLS_STR available from PHP 7.85.0
294 if (version_compare(PHP_VERSION, '8.3.0', '>=') && version_compare(curl_version()['version'], '7.85.0', '>=')) {
295 curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS_STR, implode(",", array_keys($redir_list)));
296 }
297 */
298
299 // Getting response from server
300 $response = curl_exec($ch); // return false on error, result on success
301
302 $info = curl_getinfo($ch); // Reading of request must be done after sending request
303 $http_code = $info['http_code'];
304
305 if ($followlocation && ($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307)) {
306 $newUrl = $info['redirect_url'];
307 $maxRedirection--;
308 // TODO Use $info['local_ip'] and $info['primary_ip'] ?
309 continue;
310 }
311
312 $http_code = 0;
313 } while ($http_code); // Stop if http_code is 0
314
315 $request = curl_getinfo($ch, CURLINFO_HEADER_OUT); // Reading of request must be done after sending request
316
317 dol_syslog("getURLContent request without content body=".$request);
318 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
319 // This may contains binary data, so we don't output response by default.
320 dol_syslog("getURLContent request without body=".$request, LOG_DEBUG, 0, '_curl');
321 dol_syslog("getURLContent response=".$response, LOG_DEBUG, 0, '_curl');
322 }
323 dol_syslog("getURLContent response size=".strlen($response)); // This may contains binary data, so we don't output it
324
325 $rep = array();
326 if (curl_errno($ch)) {
327 // Add keys to $rep
328 if ($response) {
329 $rep['content'] = (string) $response;
330 } else {
331 $rep['content'] = '';
332 }
333
334 $rep['http_code'] = 0;
335 $rep['curl_error_no'] = curl_errno($ch);
336 $rep['curl_error_msg'] = curl_error($ch);
337
338 dol_syslog("getURLContent response array is ".implode(',', $rep));
339 if (getDolGlobalInt('MAIN_CURL_DEBUG')) {
340 dol_syslog("getURLContent curl_error_no=".$rep['curl_error_no']." curl_error_msg=".$rep['curl_error_msg'], LOG_DEBUG, 0, '_curl');
341 }
342 } else {
343 //$info = curl_getinfo($ch);
344
345 // Return all fields found into $info.
346 $rep = $info;
347 //$rep['header_size'] = $info['header_size'];
348 //$rep['http_code'] = $info['http_code'];
349 //$rep['content_type'] = $info['http_code'];
350
351 dol_syslog("getURLContent http_code=".$rep['http_code']);
352
353 // Add more keys to $rep
354 if ($response) {
355 $rep['content'] = (string) $response;
356 if (getDolGlobalInt('MAIN_CURL_GET_RESPONSE_HEADER')) { // In this case, response contains header + body
357 $rep['header'] = substr($rep['content'], 0, intval($rep['header_size']));
358 $rep['content'] = substr($rep['content'], intval($rep['header_size']));
359 }
360 } else {
361 $rep['content'] = '';
362 }
363
364 $rep['curl_error_no'] = 0;
365 $rep['curl_error_msg'] = '';
366 }
367
368 //closing the curl
369 curl_close($ch);
370
371 // We must exclude phpstant wwarning, because all fields found in result of curl_getinfo may not be all defined into description of this method.
372 // @phpstan-ignore-next-line
373 return $rep;
374}
375
383function isIPAllowed($iptocheck, $localurl)
384{
385 if ($localurl == 0) { // Only external url allowed (dangerous, may allow to get malware)
386 if (!filter_var($iptocheck, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
387 // Deny ips like 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 0.0.0.0/8, 169.254.0.0/16, 127.0.0.0/8 et 240.0.0.0/4, ::1/128, ::/128, ::ffff:0:0/96, fe80::/10...
388 $errormsg = 'Error bad hostname IP (private or reserved range). Must be an external URL.';
389 return $errormsg;
390 }
391 if (!empty($_SERVER["SERVER_ADDR"]) && $iptocheck == $_SERVER["SERVER_ADDR"]) {
392 $errormsg = 'Error bad hostname IP (IP is a local IP). Must be an external URL.';
393 return $errormsg;
394 }
395 if (getDolGlobalString('MAIN_SECURITY_ANTI_SSRF_SERVER_IP') && in_array($iptocheck, explode(',', getDolGlobalString('MAIN_SECURITY_ANTI_SSRF_SERVER_IP')))) {
396 $errormsg = 'Error bad hostname IP (IP is a local IP defined into MAIN_SECURITY_SERVER_IP). Must be an external URL.';
397 return $errormsg;
398 }
399 }
400 if ($localurl == 1) { // Only local url allowed (dangerous, may allow to get metadata on server or make internal port scanning)
401 // Deny ips NOT like 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 0.0.0.0/8, 169.254.0.0/16, 127.0.0.0/8 et 240.0.0.0/4, ::1/128, ::/128, ::ffff:0:0/96, fe80::/10...
402 if (filter_var($iptocheck, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
403 $errormsg = 'Error bad hostname '.$iptocheck.'. Must be a local URL.';
404 return $errormsg;
405 }
406 if (getDolGlobalString('MAIN_SECURITY_ANTI_SSRF_SERVER_IP') && !in_array($iptocheck, explode(',', getDolGlobalString('MAIN_SECURITY_ANTI_SSRF_SERVER_IP')))) {
407 $errormsg = 'Error bad hostname IP (IP is not a local IP defined into list MAIN_SECURITY_SERVER_IP). Must be a local URL in allowed list.';
408 return $errormsg;
409 }
410 }
411
412 // Common check on ip (local and external)
413 // See list on https://tagmerge.com/gist/a7b9d57ff8ec11d63642f8778609a0b8
414 // Not evasive url that ar enot IP are excluded by test on IP v4/v6 validity.
415 $arrayofmetadataserver = array(
416 '100.100.100.200' => 'Alibaba',
417 '192.0.0.192' => 'Oracle',
418 '192.80.8.124' => 'Packet',
419 '100.88.222.5' => 'Tencent cloud',
420 );
421 foreach ($arrayofmetadataserver as $ipofmetadataserver => $nameofmetadataserver) {
422 if ($iptocheck == $ipofmetadataserver) {
423 $errormsg = 'Error bad hostname IP (Used by '.$nameofmetadataserver.' metadata server). This IP is forbidden.';
424 return $errormsg;
425 }
426 }
427
428 return '';
429}
430
440function getDomainFromURL($url, $mode = 0)
441{
442 $arrayof2levetopdomain = array(
443 'co.at', 'or.at', 'gv.at',
444 'avocat.fr', 'aeroport.fr', 'veterinaire.fr',
445 'com.ng', 'gov.ng', 'gov.ua', 'com.ua', 'in.ua', 'org.ua', 'edu.ua', 'net.ua',
446 'net.uk', 'org.uk', 'gov.uk', 'co.uk',
447 'com.mx'
448 );
449
450 // Set if tld is on 2 levels
451 $tldon2level = 0;
452 $parts = array_reverse(explode('.', $url));
453 if (!empty($parts[1]) && in_array($parts[1].'.'.$parts[0], $arrayof2levetopdomain)) {
454 $tldon2level = 1;
455 }
456
457 if ($tldon2level && $mode > 0) {
458 $mode++;
459 }
460
461 $tmpdomain = preg_replace('/^https?:\/\/[^:]+:[^@]+@/i', '', $url); // Remove http(s)://login@pass in https://login@pass:mydomain.com/path, so we now got mydomain.com/path
462 $tmpdomain = preg_replace('/^https?:\/\//i', '', $tmpdomain); // Remove http(s)://
463 $tmpdomain = preg_replace('/\/.*$/i', '', $tmpdomain); // Remove part after /
464 $tmpdomain = preg_replace('/^[^@]+@/i', '', $tmpdomain); // Remove part1@ in part1@part2 (for emails)
465 if ($mode == 3) {
466 $tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)\.([^\.]+)\.([^\.]+)$/', '\1.\2.\3.\4', $tmpdomain);
467 } elseif ($mode == 2) {
468 $tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)\.([^\.]+)$/', '\1.\2.\3', $tmpdomain); // Remove part 'www.' before 'abc.mydomain.com'
469 } elseif ($mode == 1) {
470 $tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)$/', '\1.\2', $tmpdomain); // Remove part 'www.abc.' before 'mydomain.com'
471 }
472
473 if (empty($mode)) {
474 if ($tldon2level) {
475 $tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)\.([^\.]+)$/', '\1.\2.\3', $tmpdomain); // Remove part 'www.abc.' before 'mydomain.com'
476 $tmpdomain = preg_replace('/\.[^\.]+\.[^\.]+$/', '', $tmpdomain); // Remove TLD (.com.mx, .co.uk, ...)
477 } else {
478 $tmpdomain = preg_replace('/^.*\.([^\.]+)\.([^\.]+)$/', '\1.\2', $tmpdomain); // Remove part 'www.abc.' before 'mydomain.com'
479 $tmpdomain = preg_replace('/\.[^\.]+$/', '', $tmpdomain); // Remove TLD (.com, .net, ...)
480 }
481 }
482
483 return $tmpdomain;
484}
485
495function getRootURLFromURL($url)
496{
497 return preg_replace('/^([a-z]*:\/\/[^\/]*).*/i', '$1', $url);
498}
499
506function removeHtmlComment($content)
507{
508 $content = preg_replace('/<!--[^\-]+-->/', '', $content);
509 return $content;
510}
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getDomainFromURL($url, $mode=0)
Function get second level domain name.
getURLContent($url, $postorget='GET', $param='', $followlocation=1, $addheaders=array(), $allowedschemes=array('http', 'https'), $localurl=0, $ssl_verifypeer=-1, $timeoutconnect=0, $timeoutresponse=0, $otherCurlOptions=array())
Function to get a content from an URL (use proxy if proxy defined).
isIPAllowed($iptocheck, $localurl)
Is IP allowed.
getRootURLFromURL($url)
Function root url from a long url For example: https://www.abc.mydomain.com/dir/page....
removeHtmlComment($content)
Function to remove comments into HTML content.