跟大家介紹php參數過濾及php資料過濾,包含php提交資料過濾的基本原則,php簡單的資料過濾
php提交資料過濾的基本原則
1)提交變數進資料庫時,我們必須使用addslashes()進行過濾,像我們的注入問題,一個addslashes()也就搞定了。其實在涉及變數取值時,intval()函數對字串的篩選也是個不錯的選擇。
2)在php.ini開啟magic_quotes_gpc和magic_quotes_runtime。 magic_quotes_gpc可以把get,post,cookie裡的引號變成斜線。 magic_quotes_runtime對於進出資料庫的資料可以起到格式話的作用。其實,早在以前註入很瘋狂時,這個參數就很流行了。
3)在使用系統函數時,必須使用escapeshellarg(),escapeshellcmd()參數去過濾,這樣你也可以放心的使用系統函數。
4)對於跨站,strip_tags(),htmlspecialchars()兩個參數都不錯,對於使用者提交的的帶有html和php的標記都會轉換。例如尖括號"<"就將轉換成 "<"這樣無害的字元。
#
$new = htmlspecialchars("<a href='test'>Test</a>", ENT_QUOTES);
strip_tags($text,);
5)對於相關函數的過濾,就像先前的include(),unlink,fopen()等等,只要你把你所要執行操作的變數指定好或對相關字元過濾嚴密
本站所有資源皆由網友貢獻或各大下載網站轉載。請自行檢查軟體的完整性!本站所有資源僅供學習參考。請不要將它們用於商業目的。否則,一切後果都由您負責!如有侵權,請聯絡我們刪除。聯絡方式:admin@php.cn
相關文章

18Jan2025
SQL Server 中的條件 WHERE 子句在 SQL Server 中,條件 WHERE 子句可讓您根據...指定不同的篩選條件。

11Nov2024
在 Angular ng-repeat 中顯示過濾後的資料計數當使用 ng-repeat 在 Angular 中顯示過濾後的資料時,準確地...

08Nov2024
在 ng-repeat 中顯示過濾數據的長度在 Angular 應用程式中,通常使用 ng-repeat 指令顯示數據,該指令會迭代...


Hot Tools

php常用表單驗證類別
php常用表單驗證類別

PHP程式碼實作表單資料驗證類別庫
PHP程式碼實作表單資料驗證類別庫

validation資料驗證庫
validation資料驗證庫

功能齊全的php驗證類
功能齊全的php驗證類

validation-Laravel的驗證庫
validation-Laravel的驗證庫
