mirror of
https://github.com/php/web-php.git
synced 2026-03-24 07:12:16 +01:00
- Use file_get_contents() if possible
- Set default context if possible (needed for get_headers())
This commit is contained in:
@@ -177,12 +177,17 @@ function header_nocache()
|
||||
// Compatibility function to fetch data from external source
|
||||
function fetch_contents($url, $headers = false) {
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.0.0', '>')) {
|
||||
if(function_exists('file_get_contents') && ini_get('allow_url_fopen')) {
|
||||
$opts = array('user_agent' => 'php.net');
|
||||
$context = stream_context_create(array('http' => $opts));
|
||||
$data = @file_get_contents($url, false, $context);
|
||||
if(function_exists('file_get_contents') && ini_get('allow_url_fopen')) {
|
||||
$context = null;
|
||||
$opts = array('user_agent' => 'php.net');
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.1.0', '>')) {
|
||||
$context = stream_context_get_defaul(array('http' => $opts));
|
||||
}
|
||||
elseif (version_compare(PHP_VERSION, '5.0.0', '>')) {
|
||||
$context = stream_context_create(array('http' => $opts));
|
||||
}
|
||||
$data = @file_get_contents($url, false, $context);
|
||||
|
||||
if ($headers) {
|
||||
return $http_response_header;
|
||||
|
||||
Reference in New Issue
Block a user