magic_quotes_gpc合magic_quotes_runtime的區別!

來源:互聯網
上載者:User

PHP提供兩個方便我們引用資料的魔法引用函數magic_quotes_gpc和 magic_quotes_runtime,這兩個函數如果在php.ini設定為ON的時候,就會為我們引用的資料碰到單引號'和雙引號"是自動加上反 斜線,幫我們自動轉譯符號,確保資料操作的正確運行,可是我們在php不同的版本或者不同的伺服器配置下,有的magic_quotes_gpc和 magic_quotes_runtime設定為on,有的又是off,所以我們寫的程式必須符合on和off兩種情況。那麼 magic_quotes_gpc和magic_quotes_runtime兩個函數有什麼區別呢?看下面的說明:

magic_quotes_gpc
作用範圍是:WEB客戶服務端;
作用時間:請求開始是,例如當指令碼運行時.

magic_quotes_runtime
作用範圍:從檔案中讀取的資料或執行exec()的結果或是從SQL查詢中得到的;
作用時間:每次當指令碼訪問運行狀態中產生的資料.

所以

magic_quotes_gpc的設定值將會影響通過Get/Post/Cookies獲得的資料
magic_quotes_runtime的設定值將會影響從檔案中讀取的資料或從資料庫查詢得到的資料

例子說明:

$data1 = $_POST['aaa'];
$data2 = implode(file('1.txt'));
if(get_magic_quotes_gpc()){
      //把資料$data1直接寫入資料庫
}else{
      $data1 = addslashes($data1);
      //把資料$data1寫入資料庫
}
if(get_magic_quotes_runtime()){
      //把資料$data2直接寫入資料庫
//從資料庫讀出的資料要經過一次stripslashes()之後輸出
}else{
      $data2 = addslashes($data2);
      //把資料$data2寫入資料庫
//從資料庫讀出的資料直接輸出
}

另外magic_quotes_runtime可以通過set_magic_quotes_runtime設定,0 for off,1 for on。

快速連結:http://idev.yo2.cn/go/22268.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.