In a measure to improve security, Hosting365 has disabled the PHP option 'allow_url_fopen'. This would normally allow a programmer to open, include or otherwise use a remote file using a URL, rather than a local file path.
The "cURL" library provides a feature rich alternative.
We have provided some examples in this document.Fetching a web page:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
?>Alternative for file_get_contents()
Instead of:
<?php
$file_contents = file_get_contents('http://example.com/');
// display file
echo $file_contents;
?>Use this:
<?php
$ch = curl_init();
$timeout = 5;
// set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://example.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
echo $file_contents;
?>However, if you receive errors you can use this:
<?php
$site_url = 'http://example.com';
$ch = curl_init();
$timeout = 5;
// set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $site_url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
ob_start();
curl_exec($ch);
curl_close($ch);
$file_contents = ob_get_contents();o
b_end_clean();
echo $file_contents;
?>Alternative for file()
Instead of:
<?php
$lines = file('http://example.com/');
// display file line by line
foreach($lines as $line_num => $line) {
echo "Line # {$line_num} : ".htmlspecialchars($line)."\n";
}
?>Use this:
<?php
$ch = curl_init();
$timeout = 5;
// set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, 'http://example.com');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch); $lines = array();
$lines = explode("\n", $file_contents);
// display file line by line
foreach($lines as $line_num => $line) {
echo "Line # {$line_num} : ".htmlspecialchars($line)."\n";
}?>
