Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Call to undefined function curl_init() #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 56 additions & 50 deletions src/phpbrowscap/Browscap.php
Original file line number Diff line number Diff line change
Expand Up @@ -601,62 +601,68 @@ protected function _getRemoteData($url)
throw new Browscap_Exception('Cannot open the local file');
}
case self::UPDATE_FOPEN:
$file = file_get_contents($url);

if ($file !== false) {
return $file;
if (ini_get('allow_url_fopen') && function_exists('file_get_contents')) {
$file = file_get_contents($url);

if ($file !== false) {
return $file;
}
} // else try with the next possibility (break omitted)
case self::UPDATE_FSOCKOPEN:
$remote_url = parse_url($url);
$remote_handler = fsockopen($remote_url['host'], 80, $c, $e, $this->timeout);

if ($remote_handler) {
stream_set_timeout($remote_handler, $this->timeout);

if (isset($remote_url['query'])) {
$remote_url['path'] .= '?' . $remote_url['query'];
}

$out = sprintf(
self::REQUEST_HEADERS,
$remote_url['path'],
$remote_url['host'],
$this->_getUserAgent()
);

fwrite($remote_handler, $out);

$response = fgets($remote_handler);
if (strpos($response, '200 OK') !== false) {
$file = '';
while (!feof($remote_handler)) {
$file .= fgets($remote_handler);
if (function_exists('fsockopen')) {
$remote_url = parse_url($url);
$remote_handler = fsockopen($remote_url['host'], 80, $c, $e, $this->timeout);

if ($remote_handler) {
stream_set_timeout($remote_handler, $this->timeout);

if (isset($remote_url['query'])) {
$remote_url['path'] .= '?' . $remote_url['query'];
}

$out = sprintf(
self::REQUEST_HEADERS,
$remote_url['path'],
$remote_url['host'],
$this->_getUserAgent()
);

fwrite($remote_handler, $out);

$response = fgets($remote_handler);
if (strpos($response, '200 OK') !== false) {
$file = '';
while (!feof($remote_handler)) {
$file .= fgets($remote_handler);
}

$file = str_replace("\r\n", "\n", $file);
$file = explode("\n\n", $file);
array_shift($file);

$file = implode("\n\n", $file);

fclose($remote_handler);

return $file;
}

$file = str_replace("\r\n", "\n", $file);
$file = explode("\n\n", $file);
array_shift($file);

$file = implode("\n\n", $file);

fclose($remote_handler);

return $file;
}
} // else try with the next possibility
case self::UPDATE_CURL:
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $this->_getUserAgent());

$file = curl_exec($ch);

curl_close($ch);

if ($file !== false) {
return $file;
if (extension_loaded('curl')) { // make sure curl is loaded
$ch = curl_init($url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_USERAGENT, $this->_getUserAgent());

$file = curl_exec($ch);

curl_close($ch);

if ($file !== false) {
return $file;
}
} // else try with the next possibility
case false:
throw new Browscap_Exception('Your server can\'t connect to external resources. Please update the file manually.');
Expand Down