php 對輸入信息的進行安全過濾的函數(shù)代碼
更新時間:2012年06月29日 11:58:49 作者:
php 對輸入信息的過濾代碼,主要是針對php安全問題
復(fù)制代碼 代碼如下:
// define constannts for input reading
define('INPUT_GET', 0x0101);
define('INPUT_POST', 0x0102);
define('INPUT_GPC', 0x0103);
/**
* Read input value and convert it for internal use
* Performs stripslashes() and charset conversion if necessary
*
* @param string Field name to read
* @param int Source to get value from (GPC)
* @param boolean Allow HTML tags in field value
* @param string Charset to convert into
* @return string Field value or NULL if not available
*/
function get_input_value($fname, $source, $allow_html=FALSE, $charset=NULL) {
$value = NULL;
if ($source == INPUT_GET && isset($_GET[$fname]))
$value = $_GET[$fname];
else if ($source == INPUT_POST && isset($_POST[$fname]))
$value = $_POST[$fname];
else if ($source == INPUT_GPC) {
if (isset($_POST[$fname]))
$value = $_POST[$fname];
else if (isset($_GET[$fname]))
$value = $_GET[$fname];
else if (isset($_COOKIE[$fname]))
$value = $_COOKIE[$fname];
}
if (empty($value))
return $value;
// strip single quotes if magic_quotes_sybase is enabled
if (ini_get('magic_quotes_sybase'))
$value = str_replace("''", "'", $value);
// strip slashes if magic_quotes enabled
else if (get_magic_quotes_gpc() || get_magic_quotes_runtime())
$value = stripslashes($value);
// remove HTML tags if not allowed
if (!$allow_html)
$value = strip_tags($value);
// convert to internal charset
return $value;
}
用法:get_input_value('_uid', INPUT_GET)
相關(guān)文章
PHP基于array_unique實現(xiàn)二維數(shù)組去重
這篇文章主要介紹了PHP基于array_unique實現(xiàn)二維數(shù)組去重,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07基于PHP導(dǎo)出Excel的小經(jīng)驗 完美解決亂碼問題
本篇文章是對PHP導(dǎo)出Excel亂碼問題的解決方法就行了詳細的分析介紹,需要的朋友參考下2013-06-06PHP實現(xiàn)二維數(shù)組按照指定的字段進行排序算法示例
這篇文章主要介紹了PHP實現(xiàn)二維數(shù)組按照指定的字段進行排序算法,涉及php針對數(shù)組的遍歷、排序等相關(guān)操作技巧,需要的朋友可以參考下2019-04-04PHP封裝的svn類使用內(nèi)置svn函數(shù)實現(xiàn)根據(jù)svn版本號導(dǎo)出相關(guān)文件示例
這篇文章主要介紹了PHP封裝的svn類使用內(nèi)置svn函數(shù)實現(xiàn)根據(jù)svn版本號導(dǎo)出相關(guān)文件,結(jié)合實例形式分析了php封裝的svn操作類與根據(jù)版本導(dǎo)出相關(guān)版本文件操作技巧,需要的朋友可以參考下2018-06-06