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)文章
關(guān)于php連接mssql:pdo odbc sql server
研究了很久,終于發(fā)現(xiàn):最新的php 5.3.6中php_mssql.dll,php_pdo_mssql.dll都已經(jīng)不見了。2011-07-07
PHP 優(yōu)化配置——加速你的VBB,phpwind,Discuz,IPB,MolyX
PHP 優(yōu)化配置——加速你的VBB,phpwind,Discuz,IPB,MolyX...2007-07-07
如何使用Laravel Eloquent來開發(fā)無限極分類
在網(wǎng)上商城上,我們經(jīng)??梢钥吹蕉嗉壏诸悺⒆臃诸?、甚至無限極分類。本文將向你展示如何優(yōu)雅的通過 Laravel Eloquent 將其實現(xiàn)。2021-05-05
PHP使用Http Post請求發(fā)送Json對象數(shù)據(jù)代碼解析
這篇文章主要介紹了PHP使用Http Post請求發(fā)送Json對象數(shù)據(jù)代碼解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-07-07
PHP函數(shù)spl_autoload_register()用法和__autoload()介紹
又是框架沖突導致__autoload()失效,用spl_autoload_register()重構(gòu)一下,問題解決2012-02-02

