A
A
Alexey Poloz2017-06-21 04:19:58
PHP
Alexey Poloz, 2017-06-21 04:19:58

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

Since I tried on different servers, the first option is no longer
available But I do not have access to php.ini
Changes in .htaccess did not help:
php_flag allow_url_fopen 1
No matter what I tried everywhere, the error is (fopen, include, urlopen)
For include, the error looks like this:
wrapper is disabled in the server configuration by allow_url_include=0

And there is no access to php.ini and .htaccess
How to get a web page or how else can I log in through my Twitter application?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Fortop, 2017-06-21
@Fortop

curl

K
Kirill Nesmeyanov, 2017-06-21
@SerafimArts

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 =)

F
Fuze, 2017-06-21
@InstantMedia

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 question

Ask a Question

731 491 924 answers to any question