2011-12-11 23 views
3

這是一個奇怪的位,我有一個PHP文件,有時會給出404錯誤。這是我製作的wordpress插件的ajax回調頁面。爲什麼一個已知的PHP文件給404?

例如:

這工作:http://ledhdtvtelevisions.com/wp-content/plugins/amazon-affiliate-link-localizer/ajax.php?strTld=co.uk&strAffiliateId=pcrev05&strLinks=B001JKTC9A|B0015TG12Q

但這並不:http://ledhdtvtelevisions.com/wp-content/plugins/amazon-affiliate-link-localizer/ajax.php?strAction=search&strLink=http://www.amazon.com/dp/B000IZGIA8

顯然,PHP文件是存在的還是第一個鏈接是行不通的,所以爲什麼不第二個鏈接工作?

有趣的是,使用完全相同的代碼我的服務器上的麻煩鏈接做工精細:http://petewilliams.info/blog2/wp-content/plugins/amazon-affiliate-link-localizer/ajax.php?strAction=search&strLink=http://www.amazon.com/dp/B000IZGIA8

可悲的是我沒有說是有問題的服務器直接訪問,但是我可以要求改變被製造。這不僅僅是這個網站有問題,腳本的其他用戶也有同樣的問題。

下面是該文件的源代碼,沒有太多吧:

<?php 

header("Content-type: application/javascript"); 

switch ($_REQUEST['strAction']) { 
    case 'search': 
     searchLink(); 
     break; 
    case 'version': 
     echo "1.7b"; 
     break; 
    default: 
     checkLinks(); 
     break; 
} 

function checkLinks() { 

    // get URL 
    $strTld   = $_REQUEST['strTld']; 
    $strAffiliateId = $_REQUEST['strAffiliateId']; 
    $strLinks  = $_REQUEST['strLinks']; 
    $arrLinks  = explode('|', $strLinks); 

    foreach ($arrLinks as $strAsin) { 

     $strLink = "http://www.amazon.$strTld/exec/obidos/ASIN/$strAsin/$strAffiliateId"; 

     $arrHeaders = get_headers($strLink, 1); 

     // if not found, then search for it 
     if (strpos($arrHeaders[0], '404') || strpos($arrHeaders[1], '404')) { 
      echo "arrLinksToCheck[ '$strAsin' ].searchLink();\n"; 
     } else { 
      echo "arrLinksToCheck[ '$strAsin' ].localiseLink();\n"; 
     } 

    } 
} 

function searchLink() { 
     $strHtml = file_get_contents($_REQUEST['strLink'], false, null, -1, 100000); 

     $strPattern = '/canonical" href="http:\/\/(.*)\/(.*)\/dp\/([A-Z0-9]{10})/'; 

     preg_match($strPattern, $strHtml, $arrMatches); 
     $strTitle = str_replace( '-', '%20', $arrMatches[2]); 

     // the canonical ASIN is sometimes different to the original one which confuses the JS, so use the one in the original link 
     $strPattern2 = '/\/([A-Z0-9]{10})/'; 
     preg_match($strPattern2 , $_REQUEST['strLink'], $arrUrlMatches); 

     $strAsin = is_array($arrUrlMatches) ? $arrUrlMatches[1] : $arrMatches[3]; 

     echo "arrLinksToCheck[ '{$strAsin}' ].writeSearchLink('$strTitle');\n"; 

} 

任何人有任何想法,這是怎麼回事?

感謝

皮特

回答

1

兩個URL在腳本執行不同的代碼路徑,爲工程運行checkLinks函數作爲一個不工作的運行searchLink之一。

因此,您可以假定服務器上的某些設置不允許在searchLink中使用某些功能。

我的直接犯罪嫌疑人將看看file_get_contents

1

代碼使用看起來確定文件的訪問權限。看起來代碼正在調用searchLink(),並嘗試確定是否使用dom中的規範引用(<link rel="canonical" href="http://rads.stackoverflow.com/amzn/click/B000IZGIA8" />)中提供的url或鏈接在url中傳遞的鏈接。

我認爲你最好的選擇是在服務器上查看php錯誤日誌,看看哪些錯誤正在被記錄。如果你有shell訪問您可以發出以下命令服務器:

php -i | fgrep error_log # this will give you the location of the error file 

tail -f /path/to/error/log 

現在你有拖尾錯誤日誌,運行相同的腳本,並看到最新被記錄。

- 編輯 -

對不起沒看到你沒有訪問到生產服務器的部分。也許尾巴錯誤日誌在你的開發服務器上,即使腳本可能似乎工作,它仍然可能會在後臺記錄一些信息。

0

你有一個錯誤的URL重寫,這是沒有得到404: -

ajax.php?strAction=search&strLink=www.amazon.com 

但這些都會打成404:

ajax.php?strAction=search&strLink=http://www.amazon.com 
ajax.php?strAction=search&strLink=http%3A%2F%2Fwww.amazon.com 

看來/(甚至是urlencoded的)有已被考慮作爲重寫的一部分,
結帳您的重寫(.htaccess或在Apache配置中,或者如果您使用PHP腳本)

相關問題