最可靠方法是用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>
						</article>

						<section class="modified-date" itemprop="dateModified" content="2026-01-14T20:10:13+08:00">
							最后修改日期:							2026-01-14						</section>

						<section class="tags">
													</section>

						
													
<div id="comments" class="discussion-wrapper">
	<h3 class="section-title">
		留言	</h3>
	<div class="discussion-timeline">

		
		
		
			<div id="respond" class="comment-respond">
		<h3 id="reply-title" class="section-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-notes">发布留言必须填写的电子邮件地址不会公开。</p><div class="form-row">

			<div class="col-sm-6 my-1">
				<div class="input-group">
					<div class="input-group-prepend">
						<div class="input-group-text"><i class="fas fa-user"></i></div>
					</div>
					<input id="author" class="form-control" placeholder="留言者姓名" name="author" type="text" value="" maxlength="245" />
				</div>
			</div>
		

			<div class="col-sm-6 my-1">
				<div class="input-group">
					<div class="input-group-prepend">
						<div class="input-group-text"><i class="fas fa-envelope"></i></div>
					</div>
					<input id="email" class="form-control" placeholder="电子邮件地址" name="email" type="text" value="" maxlength="100" />
				</div>
			</div>
		

			<div class="col-sm-12 my-1">
				<div class="input-group">
					<div class="input-group-prepend">
						<div class="input-group-text"><i class="fas fa-globe"></i></div>
					</div>
					<input id="url" class="form-control" placeholder="网站" name="url" type="text" value="" maxlength="200" />
				</div>
			</div>
		
</div>

			<div class="form-row">
				<div class="col-sm-12 my-1">
					<textarea id="comment" name="comment" class="form-control" aria-required="true"></textarea>
				</div>
			</div>
		<p class="form-submit"><input name="submit" type="submit" id="submit" class="btn btn-green my-1" 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><p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="97c3bd6527" /></p><p style="display: none !important;" class="akismet-fields-container" data-prefix="ak_"><label>Δ<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js_1" name="ak_js" value="150"/><script>document.getElementById( "ak_js_1" ).setAttribute( "value", ( new Date() ).getTime() );</script></p></form>	</div><!-- #respond -->
	
	</div>
</div>

						
					
				
			</main>

						<aside id="aside-container" class="col-lg-4 col-md-4 col-sm-12" role="complementary">
									<div id="sidebar" class="sidebar">
						<section id="block-5" class="widget widget_block widget_calendar"><div class="wp-block-calendar"><table id="wp-calendar" class="wp-calendar-table">
	<caption>2026 年 4 月</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>10</td><td id="today">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 class="pad" colspan="3"> </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></section>					</div>
											</aside>
			
		</div><!-- .row -->

		
	<nav class="navigation post-navigation" aria-label="文章">
		<h2 class="screen-reader-text">文章导航</h2>
		<div class="nav-links"><div class="nav-previous"><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"><i class="fas fa-angle-left"></i> <span class="screen-reader-text">上一篇文章</span> PHP怎么选择PHP版本安装_PHP选择PHP版本安装注意【说明】</a></div><div class="nav-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"><i class="fas fa-angle-right"></i> <span class="screen-reader-text">下一篇文章</span> PHP如何用虹软ArcSoftAI_传人像照调美颜模型得效果图【新法】</a></div></div>
	</nav>
	</div><!-- .container -->

	
</div><!-- .data-schema -->


		<footer class="footer" role="contentinfo" style="
    position: relative;
    margin: 0 auto;
    text-align: center;
    width: 100%;
">
<div>著作权 © 2026 <strong><a href="https://blog.wuxhqi.com">启尚博客</a></strong>. 保留一切权利。  </div>
					<div></div>
			
		</footer>

		
	</div><!-- .wrapper -->

			<script>

		jQuery( document ).ready(function( $ ) {
			const win = $( window );
			const doc = $( document );
			const progressBar = $( 'progress' );
			const progressLabel = $( '.progress-label' );
			const setValue = () => win.scrollTop();
			const setMax = () => doc.height() - win.height();
			const setPercent = () => Math.round( win.scrollTop() / (doc.height() - win.height()) * 100 );
			const pageTitle = $( '#post-title' );
			const pageTitleTop = pageTitle.offset().top;
			const progressBarContainer = $( '.single-post-title-bar' );
			const headerNavBrand = $( '#mynote-nav-bar' );
			const progressTitle = $( '#progress-title' );
			const headerBarContainer = $( '.header .container' );

			progressLabel.text( setPercent() + '%' );
			progressBar.attr(
				{
					value: setValue(),
					max: setMax() 
				}
			);

			doc.on( 'scroll', () => {
				progressLabel.text( setPercent() + '%' );
				progressBar.attr(
					{
						value: setValue()
					} 
				);

				if ( doc.scrollTop() > headerNavBrand.height() ) {
					//headerBarContainer.fadeOut( 800 );
					progressTitle.html( pageTitle.html() );
					progressBarContainer.fadeIn( 100 );
					progressBarContainer.addClass( 'fixed-top' );
					progressBarContainer.addClass( 'slide-down' );
				} else {
					//headerBarContainer.fadeIn( 800 );
					progressBarContainer.removeClass( 'slide-down' );
					progressBarContainer.fadeOut( 100 );

					if ( progressBarContainer.hasClass( 'fixed-top' ) ) {
						setTimeout(function() {
							progressBarContainer.removeClass( 'fixed-top' );
						}, 500);
					}
				}
			});

			win.on( 'resize', () => {
				progressLabel.text( setPercent() + '%' );
				progressBar.attr(
					{
						value: setValue(), 
						max: setMax()
					} 
				);
			});

			// Sidebar switcher
			$( '#main-container' ).attr( 'data-previous-class', $( '#main-container' ).attr( 'class' ) );

			$( '.column-control .btn-counter' ).click(function() {
				var target = $( this ).attr( 'data-target' );
				if ( $( this ).hasClass( 'active' ) ) {
					$( this ).removeClass( 'active' );

					if ( target == '#aside-container' ) {
						$( '#main-container' ).attr( 'data-previous-class', $( '#main-container' ).attr( 'class' ) );
						$( '#main-container' ).attr( 'class', 'col col-sm-12' );
						$( '#aside-container' ).hide();
					}
					if ( target == '#sidebar') {
						$( target ).show();
					}
				} else {
					$( this ).addClass( 'active' );

					if ( target == '#aside-container' ) {
						$( '#main-container' ).attr( 'class', $( '#main-container' ).attr( 'data-previous-class' ) );
						$( '#aside-container' ).show();
					}
					if ( target == '#sidebar') {
						$( target ).hide();
					}
				}

			});

			// For responsive.
			$( '.markdown-body img' ).attr('height', '');
		});

		</script>
					<script>

		jQuery( document ).ready(function( $ ) {

			$( '.scroll-area a' ).on( 'click', function(e) {
				e.preventDefault();
				var movingPosition = 0;

				if ( $( this.hash ).offset().top > $( document ).height() - $( window ).height() ) {
					movingPosition = $( document ).height() - $( window ).height();
				} else {
					movingPosition = $( this.hash ).offset().top;
				}

				$( 'html, body' ).animate({
					scrollTop: movingPosition
				}, 500, 'swing' );
			});

			$( 'a.go-top' ).on( 'click' ,function(e) {
				e.preventDefault();
				$( 'html, body' ).animate( { scrollTop: 0 }, 1000 );
			});

			$( window ).scroll( function() {      
				var windowTop =  $( window ).scrollTop();
				if ( windowTop > 100 ) {
					$( 'a.go-top' ).fadeIn( 300 );
				} else {
					$( 'a.go-top' ).fadeOut( 300 );
				}
			});

			$( '#mynote-nav-bar' ).on( 'show.bs.collapse' , function () {
				$( 'body' ).addClass( 'menu-is-collapsed' );
			});

			$( '#mynote-nav-bar' ).on( 'hidden.bs.collapse' , function () {
				$( 'body' ).removeClass( 'menu-is-collapsed' );
			});
		});

		</script>
		<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/mynote/*","/*\\?(.+)"]}},{"not":{"selector_matches":"a[rel~=\"nofollow\"]"}},{"not":{"selector_matches":".no-prefetch, .no-prefetch a"}}]},"eagerness":"conservative"}]}
</script>
<script type="text/javascript" src="https://blog.wuxhqi.com/wp-includes/js/comment-reply.min.js?ver=6.9" id="comment-reply-js" async="async" data-wp-strategy="async" fetchpriority="low"></script>
<script defer type="text/javascript" src="https://blog.wuxhqi.com/wp-content/plugins/akismet/_inc/akismet-frontend.js?ver=1763702869" id="akismet-frontend-js"></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"}}
</script>
<script type="module">
/* <![CDATA[ */
/*! 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>

	<a href="javascript:void(0);" class="go-top" style="display: none">
		<i class="fas fa-arrow-up"></i>
	</a>
</body>
</html>