9

Possible Duplicate:
file_get_contents() error

Working on a script that connects to Instagram API to get photos from a certain tag. It works just fine on Local but on the server i get errors.

Warning: file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0 in /storage/content/91/103391/instaboll.nu/public_html/instagram.php on line 19.

This is how line 19 looks:
$contents = file_get_contents("https://api.instagram.com/v1/tags/$tag/media/recent?client_id=$client_id");

Any ideas?

Have searched for this and find some posts that recommend curl, but have no idea how to proceed with that.

Community
  • 1
  • 1
blytung
  • 425
  • 1
  • 3
  • 12

4 Answers4

19

I solved it with this code.

<?php
$url = "http://www.example.org/";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$contents = curl_exec($ch);
if (curl_errno($ch)) {
  echo curl_error($ch);
  echo "\n<br />";
  $contents = '';
} else {
  curl_close($ch);
}

if (!is_string($contents) || !strlen($contents)) {
echo "Failed to get contents.";
$contents = '';
}

echo $contents;
?>    
blytung
  • 425
  • 1
  • 3
  • 12
  • 2
    I ran into this, found your thread, but needed cookies and other useful things with the cURL. I ended up posting my solution over at the following thread, if its useful to someone else. http://stackoverflow.com/questions/12885538/php-curl-and-cookies – Doug Feb 21 '14 at 21:18
  • Worked for me. I was using `file_get_contents` and there was a error `403 Forbidden` and `file_get_contents` was showing nothing. But this solved my issue. Thank You so much. @blytung – Piyush Srivastava Aug 17 '17 at 12:54
4

The solution is in the error message: set allow_url_fopen to 1 in your ini (use a php.ini file, use ini_set in php code, or talk to your host).

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • Is it just to create a php.ini file and add it to the folder were i host the other files? How do I use ini_set? – blytung Jun 11 '12 at 15:10
  • The ini file used by the server depends on the server. With apache, you may be able to use `suPHP_ConfigPath`, but maybe not. `ini_set`: http://us.php.net/manual/en/function.ini-set.php – Explosion Pills Jun 11 '12 at 15:17
  • Security guides tell us to turn it off. How can we disable it except for external URLs? I.e., don't allow it for local resources because it could allow an attacker to read sensitive information. – jww Jul 22 '16 at 12:13
2

You will have to enable allow_url_fopen from php.ini on your host or talk to your hosting providers.

This option enables the URL-aware fopen wrappers that enable accessing URL object like files.

Sarfraz
  • 377,238
  • 77
  • 533
  • 578
  • Security guides tell us to turn it off. How can we disable it except for external URLs? I.e., don't allow it for local resources because it could allow an attacker to read sensitive information. – jww Jul 22 '16 at 12:11
2

Your server admin has disabled this functionality. You'll need to ask them to enable it.

cdhowie
  • 158,093
  • 24
  • 286
  • 300