我正在使用自定义函数,并且如果此动态命名的自定义函数不存在,我想重定向到另一个脚本。由于功能存在,因此该代码段可以正确执行:
$a = '1';
call_user_func('prefix_'.$a);
function prefix_1(){}
在这种情况下,找不到该函数并生成错误。
$a = '2';
call_user_func('prefix_'.$a);
function prefix_1(){}
我需要将脚本重定向到另一个页面,例如使用header ('location: error.php');
。
先感谢您。
1.使用function_exists检查功能是否存在
2.使用IF条件重定向error.php
3.如果该功能不存在,则条件转到其他部分。
if(function_exists('prefix_'.$a)){
call_user_func('prefix_'.$a);
}else{
header("Location: http://www.example.com/error.php");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句