当前位置: 首页 > 图文教程 > 网络编程 > PHP > Get或Post提交值的非法数据处理

PHP
PHP中在数据库中保存Checkbox数据(1)
VFP与其他应用程序的集成
用PHP生成自己的LOG文件
用PHP实现文件上传二法
第七节 类的静态成员 [7]
第十三节 对象串行化 [13]
用 php 编写的日历
php+dbfile开发小型留言本
第十四节 命名空间 [14]
第十二节 类的自动加载 [12]
第十一节 重载 [11]
PHP4之真OO
在apache下限制每个虚拟主机的并发数!!!!
跟我学小偷程序之成功偷取首页(第三天)
在PHP中使用XML
使用PHP模拟HTTP认证
一个阿拉伯数字转中文数字的函数
通过对php一些服务器端特性的配置加强php的安全
在Zeus Web Server中安装PHP语言支持
PHP中实现图片的锐化

PHP 中的 Get或Post提交值的非法数据处理


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 78 ::
收藏到网摘: n/a


Get或Post提交值的非法数据处理 <?php
//********************************************************
//-- 程序名称:StrSwap V1.01
//-- 程序编写:[email][email protected][/email]
//-- 完成: 2002-8-1
//-- 程序用途:Get或Post提交值的非法数据处理
//-- 备注: 本程序需要加载在所有程序处理前使用,以便自动进行
//-- 程序中使用的变量的替换
//-- 由于发现严重BUG紧急升级
//-- Copyright By cngift ◎ 2002
//********************************************************
class StrSwap{
//当以Get方式提交变量时用于连接变量的连接符
var $GetSplitStr = "&&";
var $TempArray = array();
var $VariableArray = array();
//********************************************************
//-- 程序名称:Main()
//-- 程序用途:本类的默认运行方式
//-- 传入参数:无
//********************************************************
function Main(){
global $REQUEST_METHOD;
if("GET"==$REQUEST_METHOD){
$this->SubGetStrToArray();
}
if("POST"==$REQUEST_METHOD){
$this->SubPostStrToArray();
}
$this->GlobalVariable();

}
//********************************************************
//-- 程序名称:SubGetStrToArray()
//-- 程序用途:当变量以Get方式提交时所调用的方法
//-- 传入参数:无
//********************************************************
function SubGetStrToArray(){
global $QUERY_STRING;
$this->TempArray = explode($this->GetSplitStr,$QUERY_STRING);
for($i=0;$i<sizeof($this->TempArray);$i++){
$temp = explode('=',$this->TempArray[$i]);
$this->VariableArray[$i][0] = $temp[0];
$this->VariableArray[$i][1] = $this->StrReplace($temp[1]);
}
}
//********************************************************
//-- 程序名称:SubPostStrToArray()
//-- 程序用途:当变量以POST方式提交时所调用的方法
//-- 传入参数:无
//********************************************************
function SubPostStrToArray(){
global $_POST;
reset($_POST);
for($i=0;$i<count($_POST);$i++){
$this->VariableArray[$i][0] = key($_POST);
$this->VariableArray[$i][1] = $this->StrReplace($_POST[key($_POST)]);
next($_POST);
}
}
//********************************************************
//-- 程序名称:StrReplace()
//-- 程序用途:替换变量中的非法字符
//-- 传入参数:变量值
//********************************************************
function StrReplace($str){
$str = StripSlashes($str);
$str = str_replace(chr(92),'',$str);
$str = str_replace(chr(47),'',$str);
$str = str_replace(chr(10).chr(13),"<br>",$str);
$str = str_replace('<',"<",$str);
$str = str_replace('>',">",$str);
$str = str_replace(';',";",$str);
$str = str_replace('"',"“",$str);
$str = str_replace("'","‘",$str);
$str = str_replace(" "," ",$str);
$str = str_replace("/**/"," ",$str);
return trim($str);
}
//********************************************************
//-- 程序名称:GlobalVariable()
//-- 程序用途:声明变量为全局变量方便其他程序调用
//-- 传入参数:无
//********************************************************
function GlobalVariable(){
for($i=0;$i<sizeof($this->VariableArray);$i++){
global $$this->VariableArray[$i][0];
${$this->VariableArray[$i][0]} = $this->VariableArray[$i][1];
}
}
}
?>