[PHP] magicQuote.php – 用PHP實作magic_quotes_gpc (適用於新環境舊架構)

Magic Quote新版PHP已不支援,但如果遇到舊架構放新環境,還是在Bootstrap就模擬Magic Quote即可治標。

PHP官方Magic Quote:
Warning: This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.

以下為遞迴對輸入做addslashes處理達到magic_quotes_gpc:

function addslashesRecursively(&$data)
{
    // print_r($data);exit;

    if (!is_array($data)) {

        $data = addslashes($data);

    } else {

        foreach ($data as $key => $value) {

            addslashesRecursively($data[$key]);
        } 
    }
}

addslashesRecursively($_POST);

實作出的Helper可以參考:https://github.com/nickyidas/magicQuote.php
為靜態物件供套用。

Leave a Reply

Your email address will not be published. Required fields are marked *