Answer the question
In order to leave comments, you need to log in
PHP How to get a web page if file_get_contents doesn't work?
I need to get the keys from Twitter, but an error occurs failed to open stream: Connection refused
. Either the server is blocked, or I do not have permission in php.ini:
allow_url_fopen=Yes
allow_url_include=Off
php_flag allow_url_fopen 1
wrapper is disabled in the server configuration by allow_url_include=0
Answer the question
In order to leave comments, you need to log in
Just in case, I remind you that a full-fledged VPS \ VDS (on which you can do anything) costs from 100 rubles per month. So I'm subtly hinting that in 2017 hosting, in which even changing the ini is not an option, it seems like they should already die out, because there is more than no sense in them, at such prices. Especially with such shitty settings =)
function file_get_contents_from_url($url){
$data = file_get_contents($url);
if ($data === false){
if (function_exists('curl_init')){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 5);
$data = curl_exec($curl);
curl_close($curl);
}
}
return $data;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question