时时商务社区

标题: php 对输入信息的进行安全过滤的函数代码 [打印本页]

作者: qz234    时间: 2018-2-14 08:28

            [U]复制代码[/U] 代码如下:
// 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)
            
            
您可能感兴趣的文章:
  • php htmlentities和htmlspecialchars 的区别
  • php 字符过滤类,用于过滤各类用户输入的数据
  • php htmlspecialchars加强版
  • php HtmlReplace输入过滤安全函数
  • PHP开发不能违背的安全规则 过滤用户输入
  • php htmlspecialchars()与shtmlspecialchars()函数的深入分析
  • php 去除html标记--strip_tags与htmlspecialchars的区别详解
  • php中filter函数验证、过滤用户输入的数据
  • PHP关于htmlspecialchars、strip_tags、addslashes的解释
  • php5.4以上版本GBK编码下htmlspecialchars输出为空问题解决方法汇总
  • php htmlentities()函数的定义和用法
  • php过滤输入操作之htmlentities与htmlspecialchars用法分析
            




    欢迎光临 时时商务社区 (http://bbs.4435.cn/) Powered by Discuz! X3.2