Get或Post提交值的非法數(shù)據(jù)處理<?php
//******************************************************** //-- 程序名稱:StrSwap V1.01 //-- 程序編寫:cngift@163.com //-- 完成: 2002-8-1 //-- 程序用途:Get或Post提交值的非法數(shù)據(jù)處理 //-- 備注: 本程序需要加載在所有程序處理前使用,以便自動(dòng)進(jìn)行 //-- 程序中使用的變量的替換 //-- 由于發(fā)現(xiàn)嚴(yán)重BUG緊急升級(jí) //-- Copyright By cngift ◎ 2002 //********************************************************
class StrSwap{
//當(dāng)以Get方式提交變量時(shí)用于連接變量的連接符 var $GetSplitStr = "&&"; var $TempArray = array(); var $VariableArray = array();
//******************************************************** //-- 程序名稱:Main() //-- 程序用途:本類的默認(rèn)運(yùn)行方式 //-- 傳入?yún)?shù):無 //********************************************************
function Main(){
global $REQUEST_METHOD; if("GET"==$REQUEST_METHOD){
$this->SubGetStrToArray();
} if("POST"==$REQUEST_METHOD){
$this->SubPostStrToArray();
}
$this->GlobalVariable();
}
//******************************************************** //-- 程序名稱:SubGetStrToArray() //-- 程序用途:當(dāng)變量以Get方式提交時(shí)所調(diào)用的方法 //-- 傳入?yún)?shù):無 //********************************************************
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() //-- 程序用途:當(dāng)變量以POST方式提交時(shí)所調(diào)用的方法 //-- 傳入?yún)?shù):無 //********************************************************
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() //-- 程序用途:替換變量中的非法字符 //-- 傳入?yún)?shù):變量值 //********************************************************
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() //-- 程序用途:聲明變量為全局變量方便其他程序調(diào)用 //-- 傳入?yún)?shù):無 //********************************************************
function GlobalVariable(){
for($i=0;$i<sizeof($this->VariableArray);$i++){
global $$this->VariableArray[$i][0]; ${$this->VariableArray[$i][0]} = $this->VariableArray[$i][1];
}
}
}
?>
|