PHP怎样检测PHPINFO信息_PHP检测PHPINFO信息调用【查看】

最可靠方法是用ob_start()捕获输出并匹配标志性HTML片段,如PHP Version或PHP Credits,同时检查disable_functions配置及CLI模式差异。

php怎样检测phpinfo信息_php检测phpinfo信息调用【查看】

怎么判断当前页面是否输出了 phpinfo() 内容

直接检测 phpinfo() 是否被调用过,PHP 本身不提供运行时钩子或状态标志。它只是立即输出 HTML 表格并返回 true(成功)或 false(失败),但不记录“是否已执行”。所以不能靠查变量或函数调用来反向确认——除非你主动拦截。

用 ob_start 拦截并检查 phpinfo() 输出内容

这是最可靠、实际可用的方法:把 phpinfo() 的输出捕获到缓冲区,再用字符串匹配判断是否真生成了标准信息表。注意必须在 phpinfo() 调用前开启输出缓冲。

  • 仅对当前请求有效,不影响其他脚本
  • 匹配 PHP Version

    PHP Credits

    等标志性 HTML 片段比匹配文字更稳定(避免语言/版本差异)

  • 若服务器禁用了 phpinfo()(如 disable_functions=phpinfo),调用会失败并触发警告,需配合 @ 抑制或 set_error_handler
ob_start();
@phpinfo();
$output = ob_get_clean();
if (strpos($output, 'PHP Version') !== false || strpos($output, '<h1>PHP Credits') !== false) {
    echo "phpinfo() 已执行且输出正常";
} else {
    echo "phpinfo() 未执行,或被禁用/出错";
}</pre>
<h3>检查 phpinfo() 是否被禁用(disable_functions)</h3>
<p>很多生产环境会通过 <code>php.ini</code> 的 <code>disable_functions</code> 关闭它。这时调用 <code>phpinfo()</code> 会返回 <code>false</code> 并抛出 <code>E_WARNING</code>。单纯看返回值不够,得结合配置检查。</p>
<ul>
<li>用 <code>ini_get('disable_functions')</code> 获取禁用函数列表,再用 <code>in_array('phpinfo', explode(',', ini_get('disable_functions')))</code> 判断</li>
<li>注意空格:<code>disable_functions = exec,passthru,phpinfo</code> 中的逗号后可能有空格,建议用 <code>array_map('trim', ...)</code> 处理</li>
<li>
<code>phpinfo()</code> 在 CLI 模式下默认不输出 HTML,而是纯文本,此时匹配逻辑要相应调整(比如搜 <code>"PHP Version"</code> 而非 HTML 标签)</li>
</ul>
<h3>
<a style="color:#f60; text-decoration:underline;" title="为什么" href="https://www.php.cn/zt/92702.html" target="_blank">为什么</a>不能用 get_defined_functions() 或 debug_backtrace() 检测</h3>
<p>因为 <code>phpinfo()</code> 是语言内置函数,不是用户定义函数,不会出现在 <code>get_defined_functions()['internal']</code> 的“已调用”列表里;<code>debug_backtrace()</code> 只能查当前调用栈,无法回溯历史调用。</p>
<div class="aritcle_card flexRow">
<div class="artcardd flexRow">
								<a class="aritcle_card_img" href="https://www.php.cn/ai/2392" title="萝卜简历"><img
										src="https://img.php.cn/upload/ai_manual/001/246/273/176352302537509.png" alt="萝卜简历"></a></p>
<div class="aritcle_card_info flexColumn">
									<a href="https://www.php.cn/ai/2392" title="萝卜简历">萝卜简历</a></p>
<p>免费在线AI简历制作工具,帮助求职者轻松完成简历制作。</p>
</p></div>
<p>								<a href="https://www.php.cn/ai/2392" title="萝卜简历" class="aritcle_card_btn flexRow flexcenter"><b></b><span>下载</span> </a>
							</div>
</p></div>
<p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<p>更关键的是:即使你在一个文件里写了 <code>phpinfo()</code>,它也可能被前面的 <code>exit</code>、<code>die</code>、异常或 <code>http_response_code(403)</code> 阻断——所以“代码存在”不等于“已执行”。真正有意义的检测,永远落在输出结果或系统配置层面。</p>
<p>最易被忽略的一点:某些安全加固模块(如 Suhosin、Hardened PHP)不仅禁用函数,还会在 <code>phpinfo()</code> 输出中自动过滤敏感字段(如 <code>$_SERVER</code>、扩展路径),此时内容虽存在,但关键信息已被裁剪——光看是否有输出还不够,得校验字段完整性。</p>
<p><a href="https://www.php.cn/faq/1980853.html">https://www.php.cn/faq/1980853.html</a></p>
		</div>

				<footer class="entry-meta" aria-label="条目 meta">
			<span class="cat-links"><span class="screen-reader-text">分类 </span><a href="https://blog.wuxhqi.com/category/backend-development/php-basic/" rel="category tag">PHP 基础</a></span> 		<nav id="nav-below" class="post-navigation" aria-label="文章">
			<div class="nav-previous"><span class="prev"><a href="https://blog.wuxhqi.com/php%e6%80%8e%e4%b9%88%e9%80%89%e6%8b%a9php%e7%89%88%e6%9c%ac%e5%ae%89%e8%a3%85_php%e9%80%89%e6%8b%a9php%e7%89%88%e6%9c%ac%e5%ae%89%e8%a3%85%e6%b3%a8%e6%84%8f%e3%80%90%e8%af%b4%e6%98%8e%e3%80%91/" rel="prev">PHP怎么选择PHP版本安装_PHP选择PHP版本安装注意【说明】</a></span></div><div class="nav-next"><span class="next"><a href="https://blog.wuxhqi.com/php%e5%a6%82%e4%bd%95%e7%94%a8%e8%99%b9%e8%bd%afarcsoftai_%e4%bc%a0%e4%ba%ba%e5%83%8f%e7%85%a7%e8%b0%83%e7%be%8e%e9%a2%9c%e6%a8%a1%e5%9e%8b%e5%be%97%e6%95%88%e6%9e%9c%e5%9b%be%e3%80%90%e6%96%b0/" rel="next">PHP如何用虹软ArcSoftAI_传人像照调美颜模型得效果图【新法】</a></span></div>		</nav>
				</footer>
			</div>
</article>

			<div class="comments-area">
				<div id="comments">

		<div id="respond" class="comment-respond">
		<h3 id="reply-title" class="comment-reply-title">发表评论 <small><a rel="nofollow" id="cancel-comment-reply-link" href="/php%e6%80%8e%e6%a0%b7%e6%a3%80%e6%b5%8bphpinfo%e4%bf%a1%e6%81%af_php%e6%a3%80%e6%b5%8bphpinfo%e4%bf%a1%e6%81%af%e8%b0%83%e7%94%a8%e3%80%90%e6%9f%a5%e7%9c%8b%e3%80%91/#respond" style="display:none;">取消回复</a></small></h3><form action="https://blog.wuxhqi.com/wp-comments-post.php" method="post" id="commentform" class="comment-form"><p class="comment-form-comment"><label for="comment" class="screen-reader-text">评论</label><textarea id="comment" name="comment" cols="45" rows="8" required></textarea></p><label for="author" class="screen-reader-text">名称</label><input placeholder="名称 *" id="author" name="author" type="text" value="" size="30" required />
<label for="email" class="screen-reader-text">电子邮箱地址</label><input placeholder="电子邮箱地址 *" id="email" name="email" type="email" value="" size="30" required />
<label for="url" class="screen-reader-text">网站地址</label><input placeholder="网站地址" id="url" name="url" type="url" value="" size="30" />
<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes" /> <label for="wp-comment-cookies-consent">在此浏览器中保存我的显示名称、邮箱地址和网站地址,以便下次评论时使用。</label></p>
<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="发表评论" /> <input type='hidden' name='comment_post_ID' value='51101' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</p></form>	</div><!-- #respond -->
	
</div><!-- #comments -->
			</div>

					</main>
	</div>

	<div class="widget-area sidebar is-right-sidebar grid-25 tablet-grid-25 grid-parent" id="right-sidebar">
	<div class="inside-right-sidebar">
		<aside id="block-22" class="widget inner-padding widget_block widget_calendar"><div class="wp-block-calendar"><table id="wp-calendar" class="wp-calendar-table">
	<caption>2026 年 7 月</caption>
	<thead>
	<tr>
		<th scope="col" aria-label="星期一">一</th>
		<th scope="col" aria-label="星期二">二</th>
		<th scope="col" aria-label="星期三">三</th>
		<th scope="col" aria-label="星期四">四</th>
		<th scope="col" aria-label="星期五">五</th>
		<th scope="col" aria-label="星期六">六</th>
		<th scope="col" aria-label="星期日">日</th>
	</tr>
	</thead>
	<tbody>
	<tr>
		<td colspan="2" class="pad"> </td><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td>
	</tr>
	<tr>
		<td>6</td><td>7</td><td>8</td><td>9</td><td id="today">10</td><td>11</td><td>12</td>
	</tr>
	<tr>
		<td>13</td><td>14</td><td>15</td><td>16</td><td>17</td><td>18</td><td>19</td>
	</tr>
	<tr>
		<td>20</td><td>21</td><td>22</td><td>23</td><td>24</td><td>25</td><td>26</td>
	</tr>
	<tr>
		<td>27</td><td>28</td><td>29</td><td>30</td><td>31</td>
		<td class="pad" colspan="2"> </td>
	</tr>
	</tbody>
	</table><nav aria-label="上个月及下个月" class="wp-calendar-nav">
		<span class="wp-calendar-nav-prev"><a href="https://blog.wuxhqi.com/2026/01/">« 1 月</a></span>
		<span class="pad"> </span>
		<span class="wp-calendar-nav-next"> </span>
	</nav></div></aside><aside id="block-23" class="widget inner-padding widget_block widget_categories"><ul class="wp-block-categories-list wp-block-categories">	<li class="cat-item cat-item-57"><a href="https://blog.wuxhqi.com/category/backend-development/api-microservices/">API 与微服务</a>
</li>
	<li class="cat-item cat-item-70"><a href="https://blog.wuxhqi.com/category/projects-cases/cms-systems/">CMS系统</a>
</li>
	<li class="cat-item cat-item-2"><a href="https://blog.wuxhqi.com/category/lifestyle/">Lifestyle</a>
</li>
	<li class="cat-item cat-item-37"><a href="https://blog.wuxhqi.com/category//mysql/">mysql</a>
</li>
	<li class="cat-item cat-item-65"><a href="https://blog.wuxhqi.com/category/database-systems/mysql-mariadb/">MySQL/MariaDB</a>
</li>
	<li class="cat-item cat-item-66"><a href="https://blog.wuxhqi.com/category/database-systems/nosql/">NoSQL</a>
</li>
	<li class="cat-item cat-item-4"><a href="https://blog.wuxhqi.com/category/others/">Others</a>
</li>
	<li class="cat-item cat-item-53"><a href="https://blog.wuxhqi.com/category/backend-development/php-basic/">PHP 基础</a>
</li>
	<li class="cat-item cat-item-55"><a href="https://blog.wuxhqi.com/category/backend-development/php-frameworks/">PHP 框架</a>
</li>
	<li class="cat-item cat-item-54"><a href="https://blog.wuxhqi.com/category/backend-development/php-advanced/">PHP 进阶</a>
</li>
	<li class="cat-item cat-item-61"><a href="https://blog.wuxhqi.com/category/frontend-development/ui-visualization/">UI与可视化</a>
</li>
	<li class="cat-item cat-item-7"><a href="https://blog.wuxhqi.com/category/wordpress/">WordPress</a>
</li>
	<li class="cat-item cat-item-60"><a href="https://blog.wuxhqi.com/category/frontend-development/frontend-frameworks/">前端框架</a>
</li>
	<li class="cat-item cat-item-59"><a href="https://blog.wuxhqi.com/category/frontend-development/frontend-basic/">基础技术</a>
</li>
	<li class="cat-item cat-item-68"><a href="https://blog.wuxhqi.com/category/programming-practices/security/">安全</a>
</li>
	<li class="cat-item cat-item-72"><a href="https://blog.wuxhqi.com/category/projects-cases/practical-projects/">实战项目</a>
</li>
	<li class="cat-item cat-item-63"><a href="https://blog.wuxhqi.com/category/development-tools/dev-environment/">开发环境</a>
</li>
	<li class="cat-item cat-item-78"><a href="https://blog.wuxhqi.com/category/others-uncategorized/to-be-categorized/">待分类</a>
</li>
	<li class="cat-item cat-item-30"><a href="https://blog.wuxhqi.com/category/technology/">技术-原创</a>
</li>
	<li class="cat-item cat-item-43"><a href="https://blog.wuxhqi.com/category/zhibiao/">指标</a>
</li>
	<li class="cat-item cat-item-56"><a href="https://blog.wuxhqi.com/category/backend-development/database/">数据库</a>
</li>
	<li class="cat-item cat-item-31"><a href="https://blog.wuxhqi.com/category/lvyou/">旅游</a>
</li>
	<li class="cat-item cat-item-58"><a href="https://blog.wuxhqi.com/category/backend-development/server-deployment/">服务器与部署</a>
</li>
	<li class="cat-item cat-item-62"><a href="https://blog.wuxhqi.com/category/development-tools/version-control/">版本控制</a>
</li>
	<li class="cat-item cat-item-76"><a href="https://blog.wuxhqi.com/category/tech-lifestyle/life-insights/">生活感悟</a>
</li>
	<li class="cat-item cat-item-71"><a href="https://blog.wuxhqi.com/category/projects-cases/ecommerce-systems/">电商系统</a>
</li>
	<li class="cat-item cat-item-32"><a href="https://blog.wuxhqi.com/category/diannao/">电脑相关</a>
</li>
	<li class="cat-item cat-item-75"><a href="https://blog.wuxhqi.com/category/tech-lifestyle/tech-news/">科技资讯</a>
</li>
	<li class="cat-item cat-item-67"><a href="https://blog.wuxhqi.com/category/programming-practices/algorithms-data-structures/">算法与数据结构</a>
</li>
	<li class="cat-item cat-item-74"><a href="https://blog.wuxhqi.com/category/internet-ops/system-operations/">系统运维</a>
</li>
	<li class="cat-item cat-item-73"><a href="https://blog.wuxhqi.com/category/internet-ops/network-protocols/">网络协议</a>
</li>
	<li class="cat-item cat-item-64"><a href="https://blog.wuxhqi.com/category/development-tools/debug-test/">调试与测试</a>
</li>
	<li class="cat-item cat-item-77"><a href="https://blog.wuxhqi.com/category/tech-lifestyle/resource-recommendation/">资源推荐</a>
</li>
	<li class="cat-item cat-item-69"><a href="https://blog.wuxhqi.com/category/programming-practices/problem-solving/">问题解决</a>
</li>
	<li class="cat-item cat-item-33"><a href="https://blog.wuxhqi.com/category/interview/">面试</a>
</li>
</ul></aside>	</div>
</div>

	</div>
</div>

<div style="margin: 0 auto;width: 215px;">
	Copyright © 2026 启尚博客
</div>
<br>
<script type="speculationrules">
{"prefetch":[{"source":"document","where":{"and":[{"href_matches":"/*"},{"not":{"href_matches":["/wp-*.php","/wp-admin/*","/wp-content/uploads/*","/wp-content/*","/wp-content/plugins/*","/wp-content/themes/generatepress/*","/*\\?(.+)"]}},{"not":{"selector_matches":"a[rel~=\"nofollow\"]"}},{"not":{"selector_matches":".no-prefetch, .no-prefetch a"}}]},"eagerness":"conservative"}]}
</script>
<script id="generate-a11y">
!function(){"use strict";if("querySelector"in document&&"addEventListener"in window){var e=document.body;e.addEventListener("pointerdown",(function(){e.classList.add("using-mouse")}),{passive:!0}),e.addEventListener("keydown",(function(){e.classList.remove("using-mouse")}),{passive:!0})}}();
</script>
<script id="generate-menu-js-before">
var generatepressMenu = {"toggleOpenedSubMenus":true,"openSubMenuLabel":"\u6253\u5f00\u5b50\u83dc\u5355","closeSubMenuLabel":"\u5173\u95ed\u5b50\u83dc\u5355"};
//# sourceURL=generate-menu-js-before
</script>
<script src="https://blog.wuxhqi.com/wp-content/themes/generatepress/assets/js/menu.min.js?ver=3.6.1" id="generate-menu-js"></script>
<script src="https://blog.wuxhqi.com/wp-includes/js/comment-reply.min.js?ver=6.9.4" id="comment-reply-js" async data-wp-strategy="async" fetchpriority="low"></script>
<script id="wp-emoji-settings" type="application/json">
{"baseUrl":"https://s.w.org/images/core/emoji/17.0.2/72x72/","ext":".png","svgUrl":"https://s.w.org/images/core/emoji/17.0.2/svg/","svgExt":".svg","source":{"concatemoji":"https://blog.wuxhqi.com/wp-includes/js/wp-emoji-release.min.js?ver=6.9.4"}}
</script>
<script type="module">
/*! This file is auto-generated */
const a=JSON.parse(document.getElementById("wp-emoji-settings").textContent),o=(window._wpemojiSettings=a,"wpEmojiSettingsSupports"),s=["flag","emoji"];function i(e){try{var t={supportTests:e,timestamp:(new Date).valueOf()};sessionStorage.setItem(o,JSON.stringify(t))}catch(e){}}function c(e,t,n){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.fillText(t,0,0);t=new Uint32Array(e.getImageData(0,0,e.canvas.width,e.canvas.height).data);e.clearRect(0,0,e.canvas.width,e.canvas.height),e.fillText(n,0,0);const a=new Uint32Array(e.getImageData(0,0,e.canvas.width,e.canvas.height).data);return t.every((e,t)=>e===a[t])}function p(e,t){e.clearRect(0,0,e.canvas.width,e.canvas.height),e.fillText(t,0,0);var n=e.getImageData(16,16,1,1);for(let e=0;e<n.data.length;e++)if(0!==n.data[e])return!1;return!0}function u(e,t,n,a){switch(t){case"flag":return n(e,"\ud83c\udff3\ufe0f\u200d\u26a7\ufe0f","\ud83c\udff3\ufe0f\u200b\u26a7\ufe0f")?!1:!n(e,"\ud83c\udde8\ud83c\uddf6","\ud83c\udde8\u200b\ud83c\uddf6")&&!n(e,"\ud83c\udff4\udb40\udc67\udb40\udc62\udb40\udc65\udb40\udc6e\udb40\udc67\udb40\udc7f","\ud83c\udff4\u200b\udb40\udc67\u200b\udb40\udc62\u200b\udb40\udc65\u200b\udb40\udc6e\u200b\udb40\udc67\u200b\udb40\udc7f");case"emoji":return!a(e,"\ud83e\u1fac8")}return!1}function f(e,t,n,a){let r;const o=(r="undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?new OffscreenCanvas(300,150):document.createElement("canvas")).getContext("2d",{willReadFrequently:!0}),s=(o.textBaseline="top",o.font="600 32px Arial",{});return e.forEach(e=>{s[e]=t(o,e,n,a)}),s}function r(e){var t=document.createElement("script");t.src=e,t.defer=!0,document.head.appendChild(t)}a.supports={everything:!0,everythingExceptFlag:!0},new Promise(t=>{let n=function(){try{var e=JSON.parse(sessionStorage.getItem(o));if("object"==typeof e&&"number"==typeof e.timestamp&&(new Date).valueOf()<e.timestamp+604800&&"object"==typeof e.supportTests)return e.supportTests}catch(e){}return null}();if(!n){if("undefined"!=typeof Worker&&"undefined"!=typeof OffscreenCanvas&&"undefined"!=typeof URL&&URL.createObjectURL&&"undefined"!=typeof Blob)try{var e="postMessage("+f.toString()+"("+[JSON.stringify(s),u.toString(),c.toString(),p.toString()].join(",")+"));",a=new Blob([e],{type:"text/javascript"});const r=new Worker(URL.createObjectURL(a),{name:"wpTestEmojiSupports"});return void(r.onmessage=e=>{i(n=e.data),r.terminate(),t(n)})}catch(e){}i(n=f(s,u,c,p))}t(n)}).then(e=>{for(const n in e)a.supports[n]=e[n],a.supports.everything=a.supports.everything&&a.supports[n],"flag"!==n&&(a.supports.everythingExceptFlag=a.supports.everythingExceptFlag&&a.supports[n]);var t;a.supports.everythingExceptFlag=a.supports.everythingExceptFlag&&!a.supports.flag,a.supports.everything||((t=a.source||{}).concatemoji?r(t.concatemoji):t.wpemoji&&t.twemoji&&(r(t.twemoji),r(t.wpemoji)))});
//# sourceURL=https://blog.wuxhqi.com/wp-includes/js/wp-emoji-loader.min.js
</script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
    var a = ["❤富强❤", "❤民主❤", "❤文明❤", "❤和谐❤", "❤自由❤", "❤平等❤", "❤公正❤", "❤法治❤", "❤爱国❤", "❤敬业❤", "❤诚信❤", "❤友善❤", "❤暴富❤", "❤发财❤", "❤一个亿❤"];

    document.body.addEventListener('click', function (e) {
        // 1. 随机选取数组内容(保证不超长度)
        var randomIndex = Math.floor(Math.random() * a.length);
        var text = a[randomIndex];

        // 2. 创建 span 元素
        var span = document.createElement('span');
        span.textContent = text;

        // 3. 设置初始样式(位置、颜色、字体等)
        var x = e.pageX;
        var y = e.pageY;
        span.style.zIndex = '99999';
        span.style.position = 'absolute';
        span.style.fontWeight = 'bold';
        span.style.left = x + 'px';
        span.style.top = (y - 20) + 'px';
        span.style.color = 'rgb(' + ~~(255 * Math.random()) + ',' + ~~(255 * Math.random()) + ',' + ~~(255 * Math.random()) + ')';

        // 4. 添加到页面
        document.body.appendChild(span);

        // 5. 使用原生 Web Animations API 实现上飘 + 淡出(替代 jQuery animate)
        var animation = span.animate(
            [
                { top: (y - 20) + 'px', opacity: 1 },   // 起始状态
                { top: (y - 180) + 'px', opacity: 0 }   // 结束状态
            ],
            {
                duration: 1500,      // 持续时间 1.5秒
                easing: 'ease-out'   // 缓动效果
            }
        );

        // 6. 动画结束后移除元素
        animation.onfinish = function () {
            span.remove();
        };
    });
});
</script>
</body>
</html>