1

I am trying to do a file_get_contents of this Demo URL
However the server has trouble with getting data from external sites. This is the error I get if I echo the file_get_contents:

Found The document has moved here. Apache/2.4 Server at spotifycharts.com Port 80

I have turned the register_global on in the php.ini file, but this doesn't help.

What would be the most logical thing to check to make sure my website is able to get data from external sites?

VIVEK-MDU
  • 2,483
  • 3
  • 36
  • 63
FabianW
  • 345
  • 4
  • 9

2 Answers2

3

Just use the https url instead of the http url:

https://spotifycharts.com/api/?type=regional&country=nl&recurrence=daily&date=latest&limit=200

Philipp
  • 15,377
  • 4
  • 35
  • 52
0

You may need to request with cURL, I don't think file_get_contents() can follow 302 redirects.

Something like this should work...

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$a = curl_exec($ch);
if (preg_match('#Location: (.*)#', $a, $r))
  $l = trim($r[1]);

How to get the real URL after file_get_contents if redirection happens?
Source

Community
  • 1
  • 1
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252