使用php函数限制用户的输入,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或更高版本.你甚至可以实现一个接口

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 );

}

这种方法遵循OOP原则,非常冗长(易于维护),并且不要求您维护可以调用哪些类的数组,哪些不能.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值