下面的函数在PHP中有什么用途?
这个函数在PHP中有什么用途下面的函数在PHP中有什么用途?,php,Php,这个函数在PHP中有什么用途 public function processApi() { $func = strtolower(trim(str_replace("/","",$_REQUEST['rquest']))); ( (int)method_exists($this,$func) > 0 ) ? $this->$func() : $this->response('',404); // If the method not exist with
public function processApi()
{
$func = strtolower(trim(str_replace("/","",$_REQUEST['rquest'])));
( (int)method_exists($this,$func) > 0 ) ? $this->$func() : $this->response('',404);
// If the method not exist with in this class, response would be "Page not found".
}
$\u请求
包含$\u GET、$\u POST和$\u COOKIE的内容。
因此,基本上您正在读取从客户机传递的方法名,并检查它是否存在于特定的上下文/类中
如果函数存在,则代码正在执行该函数,如果未找到,则返回404
但是,这很容易受到攻击,因为它公开了方法,任何用户都可以远程调用这些方法 如果函数存在于同一类中,请运行它或显示404页。非常脆弱。谢谢你的友好和有用的回复