標籤:樣本 設定 寫入 方法 關閉 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()作用和用法