search
HomeBackend DevelopmentPHP TutorialExample of how to use php probe environment to instrument your code

In our previous article, we took you to understand what a php probe is and what a php probe does. I believe everyone has a certain understanding of this. So today I use a php probe to detect the implementation of the environment. The code is shared with everyone. This article mainly shares examples of how to use php probe environment to detect code. Friends who need it can refer to it


php probe environment detection code

<?php
/*
 http://phpnow.org
 YinzCN_at_Gmail.com
*/
error_reporting(E_ALL);
define(&#39;TimeZone&#39;, +8.0);
function _GET($n) { return isset($_GET[$n]) ? $_GET[$n] : NULL; }
function _SERVER($n) { return isset($_SERVER[$n]) ? $_SERVER[$n] : &#39;[undefine]&#39;; }

if (_GET(&#39;act&#39;) == &#39;phpinfo&#39;) {
 if (function_exists(&#39;phpinfo&#39;)) phpinfo();
 else echo &#39;phpinfo() has been disabled.&#39;;
 exit;
}
$Info = array();
$Info[&#39;php_ini_file&#39;] = function_exists(&#39;php_ini_loaded_file&#39;) ? php_ini_loaded_file() : &#39;[undefine]&#39;;
if (_GET(&#39;act&#39;) == &#39;getip&#39;) {
 $i = _SERVER(&#39;SERVER_NAME&#39;).&#39;|&#39;._SERVER(&#39;REMOTE_ADDR&#39;).&#39;|&#39;._SERVER(&#39;SERVER_SOFTWARE&#39;).&#39;|&#39;.(function_exists(&#39;mysql_close&#39;)?mysql_get_client_info():&#39;&#39;).&#39;|&#39;._SERVER(&#39;DOCUMENT_ROOT&#39;);
 $c = @file_get_contents(&#39;http://phpnow.org/myip.php?&#39;.base64_encode($i));
 if (preg_match(&#39;/^\d+\.\d+\.\d+\.\d+$/&#39;, $c) == 1) echo $c;
 else echo &#39;false&#39;;
 exit;
}
function colorhost() {
 $c = array(&#39;#87cefa&#39;, &#39;#ffa500&#39;, &#39;#ff6347&#39;, &#39;#9acd32&#39;, &#39;#32cd32&#39;, &#39;#ee82ee&#39;);
 $a = str_split(_SERVER(&#39;SERVER_NAME&#39;));
 $k = $l = 0;
 foreach ($a as &$d) {
  while ($k==$l) $k = array_rand($c);
  $d = &#39;<b style="color: &#39;.$c[$k].&#39;;">&#39;.$d.&#39;</b>&#39;;
  $l = $k;
 }
 return implode(&#39;&#39;, $a);
}

function get_ea_info($name) { $ea_info = eaccelerator_info(); return $ea_info[$name]; }
function get_gd_info($name) { $gd_info = gd_info(); return $gd_info[$name]; }

define(&#39;YES&#39;, &#39;<span style="color: #008000; font-weight : bold;">Yes</span>&#39;);
define(&#39;NO&#39;, &#39;<span style="color: #ff0000; font-weight : bold;">No</span>&#39;);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PHPnow Works!</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="YinzCN" />
<meta name="reply-to" content="YinzCN@Gmail.com" />
<meta name="copyright" content="YinzCN" />
<style type="text/css">
<!--
body {
font-family : verdana, tahoma;
font-size : 12px;
margin-top : 10px;
}

form {
margin : 0;
}

table {
border-collapse : collapse;
}

.info tr td {
border : 1px solid #000000;
padding : 3px 10px 3px 10px ;
}

.info th {
border : 1px solid #000000;
font-weight : bold;
height : 16px;
padding : 3px 10px 3px 10px;
background-color : #9acd32;
}

input {
border : 1px solid #000000;
background-color : #fafafa;
}

a {
text-decoration : none;
color : #000000;
}

a:hover {
text-decoration : underline;
}

a.arrow {
font-family : webdings, sans-serif;
font-size : 10px;
}

a.arrow:hover {
color : #ff0000;
text-decoration : none;
}

.item {
white-space: nowrap;
text-align: right;
}
-->
</style>
<script type="text/JavaScript">
function $(id) { return document.getElementById(id); }

function get_ip() {
 var XMLHttp, r;
 XMLHttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
 XMLHttp.onreadystatechange = function() {
  if (XMLHttp.readyState == 4)
  {
   r = XMLHttp.responseText;
   if (r == &#39;false&#39;) $(&#39;ip_r&#39;).innerHTML = &#39;获取外网 IP 失败!&#39;;
   else $(&#39;ip_r&#39;).innerHTML = &#39;此服务器互联网 IP<br /><a href="http://&#39;+r+&#39;" style="color: #999999;">&#39;+r+&#39;</a>&#39;;
  }
 }
 XMLHttp.open("GET", "?act=getip", true);
 XMLHttp.send();
}
</script>
</head>
<body onload="get_ip();">
<p style="margin: 0 auto; width: 600px;">

<p style="height: 60px;">
 <p style="float: right; margin: 5px; text-align: center;">
  <p><a style="color: #ffa500;" href="http://phpnow.org/go.php?id=1005">为何只能本地访问?</a></p>
  <p id="ip_r" style="color: #999999;">正在获取 IP 地址</p>
 </p>

 <p style="float: left;">
  <p style="font-weight: bold; font-size: 2.2em;"><a href="<?=_SERVER(&#39;PHP_SELF&#39;)?>?" style="text-decoration: none;"><?=colorhost()?></a></p>
  <p style="margin: 5px auto;"># Let&#39;s <b style="color: #777BB4;">PHP</b> <b style="color: #FF4500;">now</b> <b>!</b></p>
 </p>
</p>

<br />

<table width="100%" class="info">
 <tr>
  <th colspan="2">Server Information</th>
 </tr>

 <tr>
  <td class="item">SERVER_NAME</td>
  <td><?=_SERVER(&#39;SERVER_NAME&#39;)?></td>
 </tr>

 <tr>
  <td class="item">SERVER_ADDR:PORT</td>
  <td><?=_SERVER(&#39;SERVER_ADDR&#39;).&#39;:&#39;._SERVER(&#39;SERVER_PORT&#39;)?></td>
 </tr>

 <tr>
  <td class="item">SERVER_SOFTWARE</td>
  <td><?=stripos(_SERVER(&#39;SERVER_SOFTWARE&#39;), &#39;PHP&#39;)?_SERVER(&#39;SERVER_SOFTWARE&#39;):_SERVER(&#39;SERVER_SOFTWARE&#39;).&#39; PHP/&#39;.PHP_VERSION?></td>
 </tr>

 <tr>
  <td class="item">PHP_SAPI</td>
  <td><?=PHP_SAPI?></td>
 </tr>

 <tr>
  <td class="item" style="color: #ff0000;">php.ini</td>
  <td><?=$Info[&#39;php_ini_file&#39;]?></td>
 </tr>

 <tr>
  <td class="item">网站主目录</td>
  <td><?=_SERVER(&#39;DOCUMENT_ROOT&#39;)?></td>
 </tr>

 <tr>
  <td class="item">Server Date / Time</td>
  <td><?=gmdate(&#39;Y-m-d&#39;, time()+TimeZone*3600)?> <?=gmdate(&#39;H:i:s&#39;, time()+TimeZone*3600)?> <span style="color: #999999;">(<?=(TimeZone<0?&#39;-&#39;:&#39;+&#39;).gmdate(&#39;H:i&#39;, abs(TimeZone)*3600)?>)</span></td>
 </tr>

 <tr>
  <td class="item">Other Links</td>
  <td>
  <a href=&#39;<?=_SERVER(&#39;PHP_SELF&#39;)?>?act=phpinfo&#39;>phpinfo()</a>
  | <?=file_exists(&#39;phpMyAdmin&#39;) ? &#39;<a href="/phpMyAdmin">phpMyAdmin</a>&#39; : &#39;<a href="http://phpnow.org">PHPnow.org</a>&#39;?>
  </td>
 </tr>
</table>

<hr />

<table width="100%" class="info">
 <tr>
  <th colspan="2">PHP 组件支持</th>
 </tr>

 <tr>
  <td class="item">Zend Optimizer</td>
  <td><?=defined(&#39;OPTIMIZER_VERSION&#39;) ? YES.&#39; / &#39;.OPTIMIZER_VERSION : NO?></td>
 </tr>

 <tr>
  <td class="item">MySQL 支持</td>
  <td><?=function_exists(&#39;mysql_close&#39;) ? YES.&#39; / client lib version &#39;.mysql_get_client_info() : NO?></td>
 </tr>

 <tr>
  <td class="item">GD library</td>
  <td><?=function_exists(&#39;gd_info&#39;) ? YES.&#39; / &#39;.get_gd_info(&#39;GD Version&#39;) : NO?></td>
 </tr>

 <tr>
  <td class="item">eAccelerator</td>
  <td><?=function_exists(&#39;eaccelerator_info&#39;) ? YES.&#39; / &#39;.get_ea_info(&#39;version&#39;) : NO?></td>
 </tr>
</table>

<hr />

<form method="post" action="<?=_SERVER(&#39;PHP_SELF&#39;)?>">
<table width="100%" class="info">
 <tr>
  <th colspan="4">MySQL 连接测试</th>
 </tr>

 <tr>
  <td>MySQL 服务器</td>
  <td><input type="text" name="mysqlHost" value="localhost" /></td>
  <td>MySQL 数据库名</td>
  <td><input type="text" name="mysqlDb" value="test" /></td>
 </tr>

 <tr>
  <td>MySQL 用户名</td>
  <td><input type="text" name="mysqlUser" value="root" /></td>
  <td>MySQL 用户密码</td>
  <td><input type="text" name="mysqlPassword" /></td>
 </tr>

 <tr>
  <td colspan="4" align="right"><input type="submit" value="连接" name="act" />  </td>
 </tr>
</table>
</form>

<?php if(isset($_POST[&#39;act&#39;])) {?>
<br />

<table width="100%" class="info">
 <tr>
  <th colspan="4">MySQL 测试结果</th>
 </tr>

<?php
$link = @mysql_connect($_POST[&#39;mysqlHost&#39;], $_POST[&#39;mysqlUser&#39;], $_POST[&#39;mysqlPassword&#39;]);
$errno = mysql_errno();
if ($link) $str1 = &#39;<span style="color: #008000; font-weight: bold;">OK</span> (&#39;.mysql_get_server_info($link).&#39;)&#39;;
else $str1 = &#39;<span style="color: #ff0000; font-weight: bold;">Failed</span><br />&#39;.mysql_error();
?>
 <tr>
  <td colspan="2">服务器 <?=$_POST[&#39;mysqlHost&#39;]?></td>
  <td colspan="2"><?=$str1?></td>
 </tr>

 <tr>
  <td colspan="2">数据库 <?=$_POST[&#39;mysqlDb&#39;]?></td>
  <td colspan="2"><?=(@mysql_select_db($_POST[&#39;mysqlDb&#39;],$link))?&#39;<span style="color: #008000; font-weight: bold;">OK</span>&#39;:&#39;<span style="color: #ff0000; font-weight: bold;">Failed</span>&#39;?></td>
 </tr>
</table>
<?}?>
<hr />

<p style="text-align: right; margin: 0;"><a href="http://validator.w3.org/check?uri=referer" style="color: #999999;">Valid XHTML 1.0 Strict</a> / <a href="http://zh.wikipedia.org/wiki/Copyleft" style="color: #008000;"><b>Copyleft</b></a> ! 2007-? by <a href="http://phpnow.org">PHPnow.org</a></p>

</p>
</body>
</html>

##Summary:

The article introducing the code for php probe environment detection ends here. I believe that many friends will have a better understanding of php probes after reading this article. I hope it will be helpful to you. Helped!

Related recommendations:

What is php probe? What does php probe do?


Use PHP probe to detect VPS server performance


php probe Used when the phpinfo() function is disabled

The above is the detailed content of Example of how to use php probe environment to instrument your code. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How do you modify data stored in a PHP session?How do you modify data stored in a PHP session?Apr 27, 2025 am 12:23 AM

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Give an example of storing an array in a PHP session.Give an example of storing an array in a PHP session.Apr 27, 2025 am 12:20 AM

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

How does garbage collection work for PHP sessions?How does garbage collection work for PHP sessions?Apr 27, 2025 am 12:19 AM

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

How can you trace session activity in PHP?How can you trace session activity in PHP?Apr 27, 2025 am 12:10 AM

Tracking user session activities in PHP is implemented through session management. 1) Use session_start() to start the session. 2) Store and access data through the $_SESSION array. 3) Call session_destroy() to end the session. Session tracking is used for user behavior analysis, security monitoring, and performance optimization.

How can you use a database to store PHP session data?How can you use a database to store PHP session data?Apr 27, 2025 am 12:02 AM

Using databases to store PHP session data can improve performance and scalability. 1) Configure MySQL to store session data: Set up the session processor in php.ini or PHP code. 2) Implement custom session processor: define open, close, read, write and other functions to interact with the database. 3) Optimization and best practices: Use indexing, caching, data compression and distributed storage to improve performance.

Explain the concept of a PHP session in simple terms.Explain the concept of a PHP session in simple terms.Apr 26, 2025 am 12:09 AM

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

How do you loop through all the values stored in a PHP session?How do you loop through all the values stored in a PHP session?Apr 26, 2025 am 12:06 AM

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

Explain how to use sessions for user authentication.Explain how to use sessions for user authentication.Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.