0

first of all, my script:

<?php
$str = file_get_contents('https://externurl');

$json = json_decode($str, true); // 
echo '<pre>' . print_r($json, true) . '</pre>';
?>

I am not aloud to share the link but it is a json file, which is ip protected. The Host of the JSON file whitelisted the IP of my domain. When I execute the file on my server, I get an empty page. In the error logs I find this:

[10-Jun-2018 18:12:48 America/New_York] PHP Warning:  file_get_contents(https://url): failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

 in /home/be/public_html/testtest/testing3.php on line 2

Then I checked with a not protected json file and I dont get this error. The IP is 100% whitelisted and is the IP of my domain.

Does it have something to do that I am on shared hosting? I am trying to solve this now for all day and read something about sending header because of the shared hosting, but I have no idea how. Am I on the right track?

sindbad
  • 1
  • 1
  • `401 Unauthorized` im betting you provided the wrong IP –  Jun 10 '18 at 22:30
  • I did not. I double checked. Thats why I am asking, if it has something to do, that I am on shared hosting. – sindbad Jun 10 '18 at 22:33
  • does `file_get_contents('https://www.google.com');` work? –  Jun 10 '18 at 22:34
  • returns an empty site and an empty error log. – sindbad Jun 10 '18 at 22:37
  • your host may not have not enable the http wrappers, but the errors should be different, ask the host and try something like curl() –  Jun 10 '18 at 22:39
  • file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address=google') returns the json. Thank you anyway. I will ask my host now, what it is about the ip adress. A second protected json file is also not working. – sindbad Jun 10 '18 at 22:42
  • could you provide a curl example? I am not familiar with. – sindbad Jun 10 '18 at 22:44
  • the manuals examples are the best http://php.net/manual/en/function.curl-exec.php –  Jun 10 '18 at 22:51
  • `echo file_get_contents('http://www.whatsmyip.org/');` see if it agrees whit what you think your server IP is –  Jun 10 '18 at 23:01
  • Thank you smith, i already used minutes ago: $str = file_get_contents('https://api.ipify.org?format=json'); And it is not the IP adress of the FTP or the domain whois. crazy. But thank you for your time. – sindbad Jun 10 '18 at 23:02
  • no reasons those 3 should match (especially on a shared host). live and learn :-) the external IP may not be static, so check that with the host. –  Jun 10 '18 at 23:04

0 Answers0