当前位置: 移动技术网 > IT编程>开发语言>PHP > Get或Post提交值的非法数据处理

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

2019年05月22日  | 移动技术网IT编程  | 我要评论

get或post提交值的非法数据处理 <?php

//********************************************************
//-- 程序名称:strswap v1.01
//-- 程序编写:[email]cngift@163.com[/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];

}

}

}

?>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网