2013-02-04 34 views
0

我試圖在遠程服務器上打開一個XML文件,但遇到一個錯誤,表示已達到重定向限制。我無法控制遙控器,所以有什麼方法可以增加這個限制嗎?或者,我應該與擁有服務器的人交談,看看他們能做什麼?已達到SimpleXML重定向限制

這是錯誤:

Warning: simplexml_load_file(http://www.server.com/search/music.xml?key=key&type=songs&p1=All%20Things%20New&p2=Elevation%20Worship) [function.simplexml-load-file]: failed to open stream: Redirection limit reached, aborting in /home/admin/public_html/art/art.php on line 4

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity " http://www.server.com/search/music.xml?key=key&type=songs&p1=All%20Things%20New&p2=Elevation%20Worship " in /home/admin/public_html/art/art.php on line 4

Fatal error: Call to a member function xpath() on a non-object in /home/admin/public_html/art/art.php on line 6

我的代碼是:

<?php 
function errorHandler($n, $m, $f, $l) { 
    header('Location: blank.png'); 
} 

set_error_handler('errorHandler'); 

$url = 'http://REMOTESERVER/search/music.xml?key=KEY&type=songs&p1=' . htmlspecialchars($_GET["track"]) . '&p2=' . htmlspecialchars($_GET["artist"]) . ''; 
$xml = simplexml_load_file($url); 

$img = $xml->xpath('//image200'); 

$large = (string)$img[0]; 

header("Location:".urldecode($large)); 
?> 
+0

您從哪裏得到該錯誤?從連接或simplexml?您是否嘗試過在瀏覽器中訪問錯誤的網址?它顯示在那裏嗎?如果沒有,是的,問問主人:)。 – mvbrakel

+0

我向問題添加了錯誤消息。 – austinhollis

+0

此外,當我從遠程服務器複製XML文件並將其保存在我的,它的工作原理。 – austinhollis

回答

0

你看到的是不是用SimpleXML這樣做的錯誤,這是PHP的透明的遠程文件訪問機制這是抱怨。您可以通過創建使用file_get_contents($url); [simplexml_load_file($url)基本上是短手simplexml_load_string(file_get_contents($url))]

的特定錯誤消息表明您要加載的URL是服務的HTTP重定向一個簡單的測試案例(狀態碼301302驗證這一點)轉發到另一個URL,然後轉發到另一個URL,依此類推。無論是長鏈還是長鏈,或者遠程服務器配置錯誤,都會造成無限循環。

請注意,這樣的重定向可能會以請求的屬性爲條件,因此將其加載到瀏覽器中的行爲可能不完全相同。但是,如果確實如此,您應該可以在Firebug等瀏覽器調試工具的Net面板中看到它。

可能的解決方案:

  • 工作出了什麼最後的網址應該是和請求,而不是重定向鏈的開始
  • 請求遠程服務器的維護,檢查它們的配置和減少鏈接重定向的數量
  • 使用PHP的cURL functions顯式獲取數據而不是將URL視爲文件名;這將使您完全控制重定向處理等選項,但顯然要更準確地獲取