Changeset 735 for trunk/lib/Utilities.inc.php
- Timestamp:
- Oct 30, 2020 11:44:05 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/Utilities.inc.php
r729 r735 1519 1519 * @since 02 May 2015 15:10:09 1520 1520 */ 1521 function httpExists($url )1521 function httpExists($url, $timeout=5) 1522 1522 { 1523 1523 $ch = curl_init($url); 1524 curl_setopt($ch, CURLOPT_TIMEOUT, 5);1524 curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 1525 1525 curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 1526 1526 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); … … 1547 1547 $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 1548 1548 return preg_match('/^[23]\d\d$/', $http_code); 1549 } 1550 1551 /* 1552 * Get a HTTP response header. 1553 * 1554 * @access public 1555 * @param string $url URL to hit. 1556 * @param string $key Name of the header to return. 1557 * @param array $valid_response_codes Array of acceptable HTTP return codes. 1558 * @return string Value of the http header. 1559 * @author Quinn Comendant <quinn@strangecode.com> 1560 * @since 28 Oct 2020 20:00:36 1561 */ 1562 function getHttpHeader($url, $key, Array $valid_response_codes=[200]) 1563 { 1564 $headers = @get_headers($url, 1); 1565 1566 if ($headers && preg_match(sprintf('/\b(%s)\b/', join('|', $valid_response_codes)), $headers[0])) { 1567 $headers = array_change_key_case($headers, CASE_LOWER); 1568 $key = strtolower($key); 1569 if (isset($headers[$key])) { 1570 return $headers[$key]; 1571 } 1572 } 1573 1574 return false; 1549 1575 } 1550 1576
Note: See TracChangeset
for help on using the changeset viewer.