I have a PHP file that can be include'd() in various places inside another page. I want to know whether it has been included inside a function. How can I do this? Thanks.
3条回答 默认 最新
- du155305 2015-03-08 14:36关注
There's a function called
debug_backtrace()
that will return the current call stack as an array. It feels like a somewhat ugly solution but it'll probably work for most cases:$allowedFunctions = array('include', 'include_once', 'require', 'require_once'); foreach (debug_backtrace() as $call) { // ignore calls to include/require if (isset($call['function']) && !in_array($call['function'], $allowedFunctions)) { echo 'File has not been included in the top scope.'; exit; } }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 VB.NET操作免驱摄像头
- ¥15 笔记本上移动热点开关状态查询
- ¥85 类鸟群Boids——仿真鸟群避障的相关问题
- ¥15 CFEDEM自带算例错误,如何解决?
- ¥15 有没有会使用flac3d软件的家人
- ¥20 360摄像头无法解绑使用,请教解绑当前账号绑定问题,
- ¥15 docker实践项目
- ¥15 利用pthon计算薄膜结构的光导纳
- ¥15 海康hlss视频流怎么播放
- ¥15 Paddleocr:out of memory error on GPU