2011-08-09 75 views
2

magic_quotes_gpc設置爲off時,Magento正在轉義撇號。當我將magic_quotes_gpc設置爲on時,Magento停止插入斜線。它完全倒退。當magic_quotes_gpc設置爲off時,引號被轉義

我不能擁有Magento的逃避我的撇號,但我也不想有magic_quotes_gpc設置爲on因爲我擔心它可能對我的網站(vBulletin論壇,WordPress的博客等其他地區的影響)。

只要注意 - Magento並不總是這樣,它只是從今天開始。

編輯:行爲將以下代碼添加到我的CMS某一頁面的佈局更新XML後開始:

<!--<reference name="content"> 
<block type="catalog/product_new" name="home.catalog.product.new" alias="product_new" template="catalog/product/new.phtml" after="cms_page"><action method="addPriceBlockType"><type>bundle</type><block>bundle/catalog_product_price</block><template>bundle/catalog/product/price.phtml</template></action></block> 
<block type="reports/product_viewed" name="home.reports.product.viewed" alias="product_viewed" template="reports/home_product_viewed.phtml" after="product_new"><action method="addPriceBlockType"><type>bundle</type><block>bundle/catalog_product_price</block><template>bundle/catalog/product/price.phtml</template></action></block> 
<block type="reports/product_compared" name="home.reports.product.compared" template="reports/home_product_compared.phtml" after="product_viewed"><action method="addPriceBlockType"><type>bundle</type><block>bundle/catalog_product_price</block><template>bundle/catalog/product/price.phtml</template></action></block> 
</reference> 
<reference name="right"> 
<action method="unsetChild"><alias>right.reports.product.viewed</alias></action> 
<action method="unsetChild"><alias>right.reports.product.compared</alias></action> 
</reference>--> 

怪異的行爲開始後,我刪除代碼,但它並沒有解決問題。

+0

您今天在服務器上更改了哪些內容?像這樣的事情通常不會自發地發生。另外,你如何測試這個。我們可以嘗試重現的示例代碼? – Nick

+0

服務器上沒有任何更改。我在修改之前做的唯一事情就是向CMS頁面的佈局更新XML添加一些代碼。我已經添加了上面的代碼。在此之前的某段時間,我對'robots.txt'做了一個小改動,以防止抓取工具訪問此CMS頁面。改變之後,一切都繼續正常工作。 – Nick

回答

4

編輯:我想通了這個問題。事實證明,Wordpress有它自己的函數來添加斜槓。從Wordpress版本3.2.1開始,你可以在/wp-includes/load.php的第530行找到功能wp_magic_quotes()

爲了解決這個問題,我在函數中註釋了所有內容(而不是函數本身,以至於阻止對未定義函數的調用)。它刪除了逃脫報價的問題。我沒有做過廣泛的測試,但根據我的理解,這可能會破壞較舊的Wordpress插件,因此請小心。

它會從這樣的:

function wp_magic_quotes() { 
    // If already slashed, strip. 
    if (get_magic_quotes_gpc()) { 
     $_GET = stripslashes_deep($_GET ); 
     $_POST = stripslashes_deep($_POST ); 
     $_COOKIE = stripslashes_deep($_COOKIE); 
    } 

    // Escape with wpdb. 
    $_GET = add_magic_quotes($_GET ); 
    $_POST = add_magic_quotes($_POST ); 
    $_COOKIE = add_magic_quotes($_COOKIE); 
    $_SERVER = add_magic_quotes($_SERVER); 

    // Force REQUEST to be GET + POST. 
    $_REQUEST = array_merge($_GET, $_POST); 
} 

這樣:

function wp_magic_quotes() { 
    // If already slashed, strip. 
    /*if (get_magic_quotes_gpc()) { 
     $_GET = stripslashes_deep($_GET ); 
     $_POST = stripslashes_deep($_POST ); 
     $_COOKIE = stripslashes_deep($_COOKIE); 
    } 

    // Escape with wpdb. 
    $_GET = add_magic_quotes($_GET ); 
    $_POST = add_magic_quotes($_POST ); 
    $_COOKIE = add_magic_quotes($_COOKIE); 
    $_SERVER = add_magic_quotes($_SERVER); 

    // Force REQUEST to be GET + POST. 
    $_REQUEST = array_merge($_GET, $_POST);*/ 
} 
+0

這可能會起作用,但a)修補Wordpress核心絕不是一個好主意,並且b)如果您打算獨立於Magento使用wordpress,則通過GET和POST HTTP參數打開一個Wordpress安全漏洞。如果您將Wordpress作爲Magento的一部分,您可能需要設置一個標誌,然後在wp_magic_quotes函數中設置條件返回......這可能會沒問題。 – Willster

+0

@Willster你可以擴展這一點,因爲我使用wordpress作爲magento的一部分,我遇到了與上面相同的問題。我會非常感興趣地學習如何設置這種方式,防止magento被打破。 –

0

應用程序/代碼/核心的頂部/法師/核心/ functions.php中有這樣的:

if (get_magic_quotes_gpc()) { 
    function mageUndoMagicQuotes($array, $topLevel=true) { 
     $newArray = array(); 
     foreach($array as $key => $value) { 
      if (!$topLevel) { 
       $newKey = stripslashes($key); 
       if ($newKey!==$key) { 
        unset($array[$key]); 
       } 
       $key = $newKey; 
      } 
      $newArray[$key] = is_array($value) ? mageUndoMagicQuotes($value, false) : stripslashes($value); 
     } 
     return $newArray; 
    } 
    $_GET = mageUndoMagicQuotes($_GET); 
    $_POST = mageUndoMagicQuotes($_POST); 
    $_COOKIE = mageUndoMagicQuotes($_COOKIE); 
    $_REQUEST = mageUndoMagicQuotes($_REQUEST); 
} 

只需將該文件複製到本地(應用程序/代碼/local/Mage/Core/functions.php)並註釋掉if語句,以便它始終運行。

// if (get_magic_quotes_gpc()) { 
    function mageUndoMagicQuotes($array, $topLevel=true) { 
     $newArray = array(); 
     foreach($array as $key => $value) { 
      if (!$topLevel) { 
       $newKey = stripslashes($key); 
       if ($newKey!==$key) { 
        unset($array[$key]); 
       } 
       $key = $newKey; 
      } 
      $newArray[$key] = is_array($value) ? mageUndoMagicQuotes($value, false) : stripslashes($value); 
     } 
     return $newArray; 
    } 
    $_GET = mageUndoMagicQuotes($_GET); 
    $_POST = mageUndoMagicQuotes($_POST); 
    $_COOKIE = mageUndoMagicQuotes($_COOKIE); 
    $_REQUEST = mageUndoMagicQuotes($_REQUEST); 
// } 

這是必需的,因爲WordPress會檢查魔術引號是否被禁用,如果它是運行魔術引號。關於這是否會發生,還有很長時間的討論,但共識是刪除該功能可能會在舊版插件或主題中打開安全漏洞,因此不要期望WordPress能夠在短時間內刪除該功能。

相關問題