2015-12-21 184 views
1

我正在尝试做一个file_get_contents这个Demo URL
但是,服务器无法从外部网站获取数据。这是我的错误,如果我附和的file_get_contents:file_get_contents请求到外部网站

找到该文件已移动 here。在spotifycharts.com的Apache/2.4服务器端口80

我在php.ini fileregister_global上,但这并不能帮助。

什么是最顺理成章的事情来检查,以确保我的网站能够从外部网站获取数据?

+1

具有u尝试使用卷曲? –

+0

不可以,请你解释一下是什么? – FabianW

+1

[如果重定向发生后如何获得文件后的实际URL \ _get \ _contents?](http://stackoverflow.com/questions/4323985/how-to-get-the-real-url-after-file -get-contents-if-redirection-happens) –

回答

0

您可能需要使用cURL请求,我不认为file_get_contents()可以关注302重定向。

这样的事情应该工作...

$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