cvs: phpweb /include site.inc

From: Date: Sat, 07 Jun 2008 10:29:45 +0000
Subject: cvs: phpweb /include site.inc
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-1886@lists.php.net to get a copy of this message
bjori Sat Jun 7 10:29:45 2008 UTC Modified files: /phpweb/include site.inc Log: - Use file_get_contents() if possible - Set default context if possible (needed for get_headers()) http://cvs.php.net/viewvc.cgi/phpweb/include/site.inc?r1=1.259&r2=1.260&diff_format=u Index: phpweb/include/site.inc diff -u phpweb/include/site.inc:1.259 phpweb/include/site.inc:1.260 --- phpweb/include/site.inc:1.259 Sat Jun 7 05:05:19 2008 +++ phpweb/include/site.inc Sat Jun 7 10:29:45 2008 @@ -1,6 +1,6 @@ <?php // -*- C++ -*- -// $Id: site.inc,v 1.259 2008/06/07 05:05:19 philip Exp $ +// $Id: site.inc,v 1.260 2008/06/07 10:29:45 bjori Exp $ // Define $MIRRORS array, and some constants include $_SERVER['DOCUMENT_ROOT'] . '/include/mirrors.inc'; @@ -177,12 +177,17 @@ // 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'); + 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); } + $data = @file_get_contents($url, false, $context); if ($headers) { return $http_response_header;

« previous php.webmaster (#1886) next »