主题:PHP关于参数处理的类
PHP处理参数主要是处理post,get,cookie,session以及配置文件等参数,下面的类可以很好的完成这方面的功能.呵呵.
<?php
/********************************************************************
*
* 类 SystemParams
* 对http中的get,put,cookie,session的参数进行处理
*
*
*
*
*********************************************************************/
class SystemParams
{
/* ð�� session, cookie, get, post��� */
function GetPassParams($type="system1")
{
switch ($type)
{
case "system1":
return self::GetPassParams1();
break;
case "system2":
return self::GetPassParams2();
break;
case "get":
return self::GetGetActParams();
break;
case "post":
return self::GetPostActParams();
break;
case "cookie":
return self::GetCookieParams();
break;
case "request":
return self::GetRequestActParams();
break;
case "session":
return self::GetSessionParams();
break;
case "configini":
return self::GetConfigIniParams();
break;
default:
return self::GetPassParams1();
break;
}
}
function GetPassParams1()
{
$passParams = array();
self::PushArray(&$passParams,self::GetCookieParams());
self::PushArray(&$passParams,self::GetSessionParams());
self::PushArray(&$passParams,self::GetRequestActParams());
return $passParams;
}
function GetPassParams2()
{
$passParams = array();
self::PushArray2(&$passParams,self::GetCookieParams());
self::PushArray2(&$passParams,self::GetSessionParams());
self::PushArray2(&$passParams,self::GetRequestActParams());
return $passParams;
}
function GetPostActParams()
{
return self::AnlysisArray($_POST);
}
function GetGetActParams()
{
return self::AnlysisArray($_GET);
}
function GetRequestActParams()
{
return self::AnlysisArray($_REQUEST);
}
function GetSessionParams()
{
session_start();
$params = self::AnlysisArray($_SESSION);
return $params;
}
function GetCookieParams()
{
$params = self::AnlysisArray($_COOKIE);
return $params;
}
function GetConfigIniParams()
{
$iniFile = SystemCommon::WebPath()."/snmp_command/config.php";
return parse_ini_file($iniFile);
}
function PushArray(&$array,$data)
{
if ( is_array($data) )
{
foreach($data as $key=>$val)
{
if ( is_array($val) )
{
self::PushArray(&$array[$key],$val);
}
else
{
$array[$key] = $val;
}
}
}
return $array;
}
function PushArray2(&$array,$data)
{
if ( is_array($data) )
{
foreach( $data as $key=>$val)
{
if ( is_array($val) )
{
self::PushArray2(&$array,$val);
}
else
{
$array[$key] = $val;
}
}
}
}
function AnlysisArray($array)
{
if ( is_array($array) )
{
foreach( $array as $key => $val)
{
if ( is_array($val) )
{
self::AnlysisArray($val);
}
else
{
/* 对参数进行防HTML攻击预处理 */
$array[$key] = SystemCommon::DelHtmlChars($val);
}
}
}
return $array;
}
}
?>
<?php
/********************************************************************
*
* 类 SystemParams
* 对http中的get,put,cookie,session的参数进行处理
*
*
*
*
*********************************************************************/
class SystemParams
{
/* ð�� session, cookie, get, post��� */
function GetPassParams($type="system1")
{
switch ($type)
{
case "system1":
return self::GetPassParams1();
break;
case "system2":
return self::GetPassParams2();
break;
case "get":
return self::GetGetActParams();
break;
case "post":
return self::GetPostActParams();
break;
case "cookie":
return self::GetCookieParams();
break;
case "request":
return self::GetRequestActParams();
break;
case "session":
return self::GetSessionParams();
break;
case "configini":
return self::GetConfigIniParams();
break;
default:
return self::GetPassParams1();
break;
}
}
function GetPassParams1()
{
$passParams = array();
self::PushArray(&$passParams,self::GetCookieParams());
self::PushArray(&$passParams,self::GetSessionParams());
self::PushArray(&$passParams,self::GetRequestActParams());
return $passParams;
}
function GetPassParams2()
{
$passParams = array();
self::PushArray2(&$passParams,self::GetCookieParams());
self::PushArray2(&$passParams,self::GetSessionParams());
self::PushArray2(&$passParams,self::GetRequestActParams());
return $passParams;
}
function GetPostActParams()
{
return self::AnlysisArray($_POST);
}
function GetGetActParams()
{
return self::AnlysisArray($_GET);
}
function GetRequestActParams()
{
return self::AnlysisArray($_REQUEST);
}
function GetSessionParams()
{
session_start();
$params = self::AnlysisArray($_SESSION);
return $params;
}
function GetCookieParams()
{
$params = self::AnlysisArray($_COOKIE);
return $params;
}
function GetConfigIniParams()
{
$iniFile = SystemCommon::WebPath()."/snmp_command/config.php";
return parse_ini_file($iniFile);
}
function PushArray(&$array,$data)
{
if ( is_array($data) )
{
foreach($data as $key=>$val)
{
if ( is_array($val) )
{
self::PushArray(&$array[$key],$val);
}
else
{
$array[$key] = $val;
}
}
}
return $array;
}
function PushArray2(&$array,$data)
{
if ( is_array($data) )
{
foreach( $data as $key=>$val)
{
if ( is_array($val) )
{
self::PushArray2(&$array,$val);
}
else
{
$array[$key] = $val;
}
}
}
}
function AnlysisArray($array)
{
if ( is_array($array) )
{
foreach( $array as $key => $val)
{
if ( is_array($val) )
{
self::AnlysisArray($val);
}
else
{
/* 对参数进行防HTML攻击预处理 */
$array[$key] = SystemCommon::DelHtmlChars($val);
}
}
}
return $array;
}
}
?>