Question

[Solved] file_get_contents not working?

This code is not working to server. But It is working to my localhost (xampp)

$url = file_get_contents('http://www.site.com/');
$xhtml='|<tr style="background-color:#dddddd;">
        <td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>
    </tr>|i';
preg_match_all($xhtml,$url,$score);
array_shift($score);
echo"<pre>";
print_r($score);
echo"</pre>";

It prints another scores when I change the code like this. Because there are two rows like this. It has same codes. by the way below code works to server.

$xhtml='|<td class="odd" align="left">(.+?)</td><td class="odd">(.+?)</td>|i';

I need to take this two values between code.

allow_url_fopen = on
Enquirer: Venom

||

Solution #1:

Try this function in place of file_get_contents():

<?php

function curl_get_contents($url)
{
    $ch = curl_init();

    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $url);

    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

It can be used just like file_get_contents(), but uses cURL.

Install cURL on Ubuntu (or other unix-like operating system with aptitude):

sudo apt-get install php5-curl
sudo /etc/init.d/apache2 restart

See also cURL

Respondent: Venom

Solution #2:

You need to allow

 allow_url_fopen

in your php.ini config file. Some hosts disallow it for security

Respondent: Adelmar

Solution #3:

I know this topic is old, but I had to figure this out on my own and figure it will help someone later.

Like the above says:

You need:

allow url fopen
allow url include

If you are using CURL then you need curl extension

If you are file_get_contents of a https:// I believe you also need apache ssl module, as well as openssl php extension.

Without OpenSSL and SSL Module doing a file_get_contents on a facebook graph (obviously https://) it returned “No file found” error.

Respondent: genesis

Solution #4:

Also check whether you have: allow_url_include On

And make sure that there are no network permission issues like 403 Forbidden.

Respondent: David Lawrence

Solution #5:

We had this issue and it turned out to be something unusual. We were trying to file_get_contents(‘https://www.google.com‘); the issue for us was because the server was set to use ipv6 but it had no ipv6 ip assigned. We disabled ipv6 and had it use ipv4 and it worked. Just another thing on the list to check.

Respondent: shasi kanth

Solution #6:

If allow_url_fopen is On then disable your firewall or csf and check again.

Respondent: henry

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy