php中的set_magic_quotes_runtime()作用和用法

來源:互聯網
上載者:User

標籤:樣本   設定   寫入   方法   關閉   fwrite   讀寫   gic   win   

set_magic_quotes_runtime 用來設定php.ini檔案中的magic_quotes_runtime值,當遇到反斜杆(\)、單引號(‘)、雙引號(")這樣一些的字元定入到資料庫裡,又不想被過濾掉,使用這個函數,將會自動加上一個反斜杆(\),保護系統和資料庫的安全。

magic_quotes_runtime 是php.ini裡的環境組態變數,0和false表示關閉本功能,1和true表示開啟本功能。當magic_quotes_runtime開啟時,所有外部引入的資料庫資料或者檔案等都會自動轉為含有反斜線溢出的資料,
設定方法如下:

1、可以直接在php.ini裡面設定為ON

2、set_magic_quotes_runtime(true)或者set_magic_quotes_runtime(1)

3、用ini_set函數,ini_set(magic_quotes_runtime,1);

樣本:

<?php

$fp=tmpfile();                      //以讀寫入模式建立一個具有唯一檔案名的臨時檔案,檔案會在關閉後自動被刪除

fwrite($fp,‘\‘PHP\‘ is a Recursive acronym‘);                //寫入資料

rewind($fp);                                //指標倒迴文件的開頭

set_magic_quotes_runtime(0);

echo ‘Without magic_quotes_runtime:‘.fread($fp,1024).‘<br />‘;            //從檔案中讀取1k

rewind($fp);

set_magic_quotes_runtime(true);

echo ‘With magic_quotes_runtime:‘.fread($fp,1024);

fclose($fp);//關閉檔案

?>

運行結果:

 

Without magic_quotes_runtime:‘PHP‘ is a Recursive acronym
With magic_quotes_runtime:\‘PHP\‘ is a Recursive acronym

php中的set_magic_quotes_runtime()作用和用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.