我想創建一個AJAX腳本,它需要兩個GET變量,類和方法,並將它們映射到我們設計的方法(類似於CodeIgniter如何代理Ajax,I很確定)。由於我依靠用戶輸入來確定要執行的類和方法,所以我擔心黑客可能會使用某種方法來利用該技術。安全地調用一個基於用戶輸入的函數
代碼:
//Grab and clean (just in case, why not) the class and method variables from GET
$class = urlencode(trim($_GET['c']));
$method = urlencode(trim($_GET['m']));
//Ensure the passed function is callable
if(method_exists($class, $method)){
$class::$method();
}
有什麼缺點或安全手錶奏我應該知道在使用這種技術的?
AjaxCallable接口是一個好主意,完美地工作。謝謝! – ACobbs 2012-07-11 13:35:10
很高興爲你工作:) – 2012-07-11 14:37:56