脚本宝典收集整理的这篇文章主要介绍了php – 根据用户输入安全地调用函数,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
代码:
//Grab and clean (just in case,why not) the class and method VARiables @R_304_2150@ GET $class = urlencode(trim($_GET['c'])); $method = urlencode(trim($_GET['m'])); //Ensure the passed function is callable if(method_exists($class,$method)){ $class::$method(); }
<?PHP class AjaxCallableFunction { public static $callable_from_ajax = TRUE; } $class = $_POST['class']; $method = $_POST['method']; if ( class_exists( $class ) && isset( $class::$callable_from_ajax ) && $class::$callable_from_ajax ) { call_user_func( $class,$method ); }
结合其他一些答案以获得最佳效果.需要PHP 5.3.0或更高版本.你甚至可以实现一个接口
<?PHP interface AjaxCallable {} class MyClass implements AjaxCallable { // Your code here } $class = $_POST['class']; $method = $_POST['method']; if ( class_exists( $class ) && in_array( 'AjaxCallable',class_implements( $class ) ) ) { call_user_func( $class,$method ); }
以上是脚本宝典为你收集整理的php – 根据用户输入安全地调用函数全部内容,希望文章能够帮你解决php – 根据用户输入安全地调用函数所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。