2009-10-10 92 views
1

我使用get_headers功能在PHP請求從本地服務器返回數組網站 頭 放的時候在我的網站使用不退貨PHP:get_headers功能結果是不同的

在返回數組

例子本地服務器

 
Array 
(
    [0] => HTTP/1.1 301 Moved 
    [Server] => Array 
     (
      [0] => nginx/0.7.42 
      [1] => Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 
      [2] => Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8e-fips-rhel5 mod_auth_passthrough/2.1 mod_bwlimited/1.4 
      [3] => Microsoft-IIS/7.0 
     ) 
    [Content-Type] => Array 
     (
      [0] => text/html; charset=utf-8 
      [1] => text/html; charset=iso-8859-1 
      [2] => text/html 
      [3] => text/html; charset=utf-8 
     ) 
    [Location] => Array 
     (
      [0] => http//3.ly/aXP 
      [1] => http//3.ly/aXP/ 
      [2] => http//stackoverflow.com 
     ) 
    [MIME-Version] => 1.0 
    [Content-Length] => Array 
     (
      [0] => 277 
      [1] => 376 
      [2] => 0 
      [3] => 122213 
     ) 
) 

在真實服務器

 
Array 
(
    [0] => HTTP/1.1 301 Moved 
    [Server] => nginx/0.7.42 
    [Date] => Sat, 10 Oct 2009 03:15:32 GMT 
    [Content-Type] => text/html; charset=utf-8 
    [Connection] => keep-alive 
    [Location] => http//3.ly/aXP 
    [MIME-Version] => 1.0 
    [Content-Length] => 277 
) 

我不會返回數組

感謝....

回答

1

似乎有是在PHP中如何處理在本地服務器上,並在真實服務器重定向的差異。我想你也會在本地獲取數組,但由於某種原因,本地get_headers()似乎不遵循重定向。

PHP版本在兩種環境中是否相同?

+0

thnk你幫忙 PHP版本 在真實服務器本地服務器5.2.6 \t 5.2.8 – Testr 2009-10-10 04:45:52

0

這似乎沒有理由。如果要在第二個參數設置爲一個非零值來獲得一個數組1

get_headers($url, 1); 

如果你這樣做,它應該在任何地方運行一樣,除非有PHP本身還是一個bug在有問題的服務器中(這兩種情況都是偶爾用戶的罕見情況)。

注意get_headers如下(多個)重定向並且存儲每個的報頭重定向作爲數組2

array(11) { 
    [0]=> 
    string(30) "HTTP/1.0 301 Moved Permanently" 
    ["Location"]=> string(22) "http://www.google.com/" 
    ["Content-Type"]=> array(2) { 
    [0]=> string(24) "text/html; charset=UTF-8" 
    [1]=> string(29) "text/html; charset=ISO-8859-1" 
    } 
... 

用於重定向的特定報頭值被連續地存儲,所以看起來Content-Type[0]可以是與Location中的任何一個相關,這使得數組格式無法正確獲取每個重定向的標題。行數組格式不太好,因爲您需要解析標題。但隨着陣列格式,你可以檢測到最後位置等