PHP网络编程技术详解由浅入深,全面、系统地介绍了PHP开发技术,并提供了大量实例,供读者实战演练。另外,笔者专门为本书录制了相应的配套教学视频,以帮助读者更好地学习本书内容。这些视频和书中的实例源代码一起收录于配书光盘中。本书共分4篇。第1篇是PHP准备篇,介绍了PHP的优势、开发环境及安装;第2篇是PHP基础篇,介绍了PHP中的常量与变量、运算符与表达式、流程控制以及函数;第3篇是进阶篇,介绍
386
/**
* 安全过滤类-过滤HTML标签
* Controller中使用方法:$this->controller->fliter_html($value)
* @param string $value 需要过滤的值
* @return string
*/
function fliter_html($value) {
if (function_exists('htmlspecialchars')) return htmlspecialchars($value);
return str_replace(array("&", '"', "'", ""), array("&", """, "'", ""), $value);
}
/**
* 安全过滤类-对进入的数据加下划线 防止SQL注入
* Controller中使用方法:$this->controller->fliter_sql($value)
* @param string $value 需要过滤的值
* @return string
*/
function fliter_sql($value) {
$sql = array("select", 'insert', "update", "delete", "'", "/*",
"../", "./", "union", "into", "load_file", "outfile");
$sql_re = array("","","","","","","","","","","","");
return str_replace($sql, $sql_re, $value);
}
/**
* 安全过滤类-通用数据过滤
* Controller中使用方法:$this->controller->fliter_escape($value)
* @param string $value 需要过滤的变量
* @return string|array
*/
function fliter_escape($value) {
if (is_array($value)) {
foreach ($value as $k => $v) {
$value[$k] = self::fliter_str($v);
}
} else {
$value = self::fliter_str($value);
}
return $value;
}
/**
* 安全过滤类-字符串过滤 过滤特殊有危害字符
* Controller中使用方法:$this->controller->fliter_str($value)
* @param string $value 需要过滤的值
* @return string
*/
function fliter_str($value) {
$badstr = array(" ", "%00", "
", '&', ' ', '"', "'", "", " ", "%3C", "%3E");
$newstr = array('', '', '', '&', ' ', '"', ''', "", " ", "");
$value = str_replace($badstr, $newstr, $value);
$value = preg_replace('/&((#(d{3,5}|x[a-fA-F0-9]{4}));)/', '&\1', $value);
return $value;
}
/**
* 私有路劲安全转化
* Controller中使用方法:$this->controller->filter_dir($fileName)
* @param string $fileName
* @return string
*/
function filter_dir($fileName) {
$tmpname = strtolower($fileName);
$temp = array(':/'," ", "..");
if (str_replace($temp, '', $tmpname) !== $tmpname) {
return false;
}
return $fileName;
}
/**
* 过滤目录
* Controller中使用方法:$this->controller->filter_path($path)
* @param string $path
* @return array
*/
public function filter_path($path) {
$path = str_replace(array("'",'#','=','`','$','%','&',';'), '', $path);
return rtrim(preg_replace('/(/){2,}|(\){1,}/', '/', $path), '/');
}
/**
* 过滤PHP标签
* Controller中使用方法:$this->controller->filter_phptag($string)
* @param string $string
* @return string
*/
public function filter_phptag($string) {
return str_replace(array(''), array(''), $string);
}
/**
* 安全过滤类-返回函数
* Controller中使用方法:$this->controller->str_out($value)
* @param string $value 需要过滤的值
* @return string
*/
public function str_out($value) {
$badstr = array("", "%3C", "%3E");
$newstr = array("", "");
$value = str_replace($newstr, $badstr, $value);
return stripslashes($value); //下划线
}
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号