/    Sign up×
Community /Pin to ProfileBookmark

get_file_contents geo blocked

I’m using a JSON file to get some information. This works perfectly on my local machine however when I load it to my shared hosting site I believe the JSON file is being blocked.

Is there a way I can send headers or do something to say it’s coming from a different location?

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 23.2022 — Can you clarify a bit? Are you trying to access this JSON from another site via a URL through file_get_contents()? If so, see the note at https://www.php.net/file_get_contents#refsect1-function.file-get-contents-notes about having to have "fopen wrappers" enabled (which can not be set at runtime, but must be in the PHP config).

For this reason, it's often best to use the cURL functions to fetch from a URL, which also provides the ability to set various HTTP headers/values when requesting, if in fact you need to do that.
Copy linkTweet thisAlerts:
@kiwisauthorFeb 23.2022 — file_get_contents works on my local machine and remote server.

The page I'm calling has some type of geo restrictions. So on my location machine it works, but my remote server is in a country which is blocked. When I call if I get 'this page is unavailable from your location' instead of the JSON I'm after.
Copy linkTweet thisAlerts:
@NogDogFeb 24.2022 — They're most likely going by your server's IP address, then. If so, not sure what you could do other than figure out a way to route it through a VPN or something...which isn't usually free (plus you'd need to find one they'd accept).
Copy linkTweet thisAlerts:
@kiwisauthorFeb 24.2022 — @NogDog#1642827

Yeah, I just thought via fopen, curl or file_get_contents there was a way of sending headers should you location. I could be wrong
Copy linkTweet thisAlerts:
@NogDogFeb 24.2022 — I doubt it's based on an HTTP header, though you never know for sure. The IP address would be what I'd use if I was serious about restricting access, since anyone with a bit of knowledge can change HTTP headers.
×

Success!

Help @kiwis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...