【发布时间】:2011-03-12 20:33:59
【问题描述】:
我目前正在为一家公司开发 MVC 样式框架,出于安全原因,我需要确保通过查询字符串传递的控制器/方法是 RFC 的有效字符(我找不到) .
我需要能够根据 PHP 解释器的允许来验证/清理类名
例如:
class SomEFunk__YClAssName extends Controller
{
}
我需要某种正则表达式来验证SomEFunk__YClAssName 并在需要时对其进行清理!这也是方法的原理。
有一些事情需要考虑,例如
- 开头的数字
- 只允许下划线
- 允许使用某些 PHP 特殊字符。
任何关于这个或可能的表达方式的信息都会很有帮助。
这是我的一些路由器代码,因此您可以看到我需要在哪里实现它:
private function prepareQueryString()
{
if(strlen($this->query_string) == 0)
{
return;
}
//Remove [ending|starting|multiple] slashes
$this->query_string = preg_replace('/^\/+|\/+$|\/(?=\/)/', '', $this->query_string);
foreach(explode('/',$this->query_string) as $Key => $Value)
{
if($Key == 0)
{
$Controller = $this->AssignController($Value);
}
if($Key == 1)
{
$this->AssignMethod($Value);
}else
{
$this->AssignParam($Value);
}
}
//Build RouterVar stdClass
}
public function AssignController(String $Controller)
{
if(!empty($Controller))
{
//Sanitize
}
}
public function AssignMethod(String $Method)
{
if(!empty($Method))
{
//Sanitize
}
}
public function AssignParam(String $Param)
{
$this->params[] = $Param;
}
您会在需要检查的地方看到注释“消毒”。
【问题讨论】: