看過我們之前的文章的小夥伴相信對php探針有所瞭解,但是有人說那都是一些理論寫東西,想看一些php探針的代碼,藉此,今天就給分享一款前台基於HTML5技術的PHP探針,在支援HTML5的瀏覽器中查看效果最佳。
本代碼可檢測PHP伺服器各個變數資訊,比如PHP伺服器的作業系統、PHP版本、上傳檔案的大小限制、目前時間、指令碼解釋引擎、已編譯模組監測、高精度數學運算等,還可檢測伺服器組件及資料庫支援監測、壓縮檔支援、IMAP電子郵件系統函數庫等,
下面是完整的探針代碼:
<!doctype html><html><head><meta charset="utf-8"><title>簡潔實用PHP探針</title><style type="text/css" >* { padding:0px; margin:0px;}li { list-style-type:none}a { color:#333;}body { background:#f2efe8; font-size:12px; color:#666; padding-top:30px; }.box { background:#FFF; border:1px solid #e1e1e1; -webkit-box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3);-moz-box-shadow:0 2px 2px rgba(0, 0, 0, 0.3));box-shadow: 0 2px 2px rgba(0, 0, 0, 0.3); width:90%; margin:0px auto; border-radius:10px; line-height:30px; padding-bottom:10px; margin-bottom:20px;}.title { background:#f5f5f5; line-height:40px; padding-left:20px; font-size:14px; color:#333; height:40px; border-bottom:1px solid #e5e5e5; border-radius:10px; border-bottom-right-radius:0px;border-bottom-left-radius:0px; }ul li { padding:0px 20px; border-bottom:1px solid #e5e5e5; margin:0px 5px; }span { margin-left:10px;}.sudu {padding: 0; background:#5dafd1; }.suduk { margin:0px; padding:0;}</style><?phperror_reporting(0);phpversion() >= '5.1.0' && date_default_timezone_set('UTC');@header("content-Type: text/html; charset=utf-8"); $stime = date("Y-n-j H:i:s");function check_os() { $uname=php_uname(); $uname=explode(" ",$uname); return $uname[0];}function check_extension() { $os=get_loaded_extensions(); for($i=0;$i<count($os);$i++) { echo $os[$i]; if(($i+1)>=15 and ($i+1)%15==0) { echo '<br />'; } else { echo ' | '; } }}function ini($ini) { if(preg_match('/0|off/i',$x=ini_get($ini))) { return 'OFF'; } elseif($x == null) { return 'NONE'; } else { return $x == 1 ? 'ON' : $x;}}function isfun($funName = '') { if (!$funName || trim($funName) == '' || preg_match('~[^a-z0-9\_]+~i', $funName, $tmp)) return '錯誤'; return (false !== function_exists($funName)) ? '<b>√</b>' : '<em>×</em>';}header("content-type:text/html;charset=UTF-8");if(isset($_GET[page])) { if($_GET['page']=="date") { echo date("Y-m-d H:i:s"); } elseif($_GET['page']=="phpinfo") { phpinfo(); } elseif($_GET['page']=="cpuinfo") { check_cpu(); } elseif($_GET['page']=="meminfo") { check_mem(); } elseif($_GET['page']=="diskinfo"){ check_disk(); } elseif($_GET['page']=="uptime") { check_uptime(); } elseif($_GET['page']=="download") { Header('Content-Type:application/octet-stream'); header('accept-length:'.filesize($path)); Header('Content-Disposition:attachment;filename=check.php'); echo file_get_contents(FILE); } exit();}if ($_POST['act'] == "開始測試") {?><script language="javascript" type="text/javascript">var acd1;acd1 = new Date();acd1ok=acd1.getTime();</script><?php for ($i = 1; $i <= 100000; $i++) { echo "<!--567890#########0#########0#########0#########0#########0#########0#########0#########012345-->"; }?><script language="javascript" type="text/javascript">var acd2;acd2 = new Date();acd2ok=acd2.getTime();window.location = '?speed=' +(acd2ok-acd1ok);</script><?php}//網速測試-結束if (isset($_POST['speed'])) { $speed = round(100 / ($_POST['speed'] / 1000), 2);} elseif ($_GET['speed'] == "0") { $speed = 6666.67;} elseif (isset($_GET['speed']) and $_GET['speed'] > 0) { $speed = round(100 / ($_GET['speed'] / 1000), 2); //下載速度:$speed kb/s} else { $speed = "<font color=\"red\"> 未探測 </font>";}function check_mysql($host,$user,$pass) { if(@mysql_connect($host,$user,$pass)) { return '<script type="text/javascript">alert("成功串連到MysqL資料庫!");</script>'; } else { return '<script type="text/javascript">alert("無法串連到MysqL資料庫!");</script>'; }}?></head><body><div class="box"><div class="title">實用探針v1.0</div></div><div class="box"><div class="title">伺服器參數</div><ul><li>伺服器系統:<?php echo check_os(); ?></li><li>PHP版本:<?php echo phpversion(); ?><a href="?page=phpinfo">PHPINFO</a></li><li>伺服器IP:<?php echo @$_SERVER['REMOTE_ADDR'];?><span>伺服器連接埠:<?php echo $_SERVER['SERVER_PORT'];?></span></li><li>伺服器解釋引擎:<?php echo $_SERVER['SERVER_SOFTWARE'];?></li><li>伺服器目前時間:<?php echo $stime;?></li><li>探針真真實位址:<?php echo $_SERVER['DOCUMENT_ROOT']?str_replace('\\','/',$_SERVER['DOCUMENT_ROOT']):str_replace('\\','/',dirname(FILE));?></li><li>上傳檔案的大小限制:<?php echo ini('upload_max_filesize'); ?></li></ul></div><div class="box"><form action="<?php echo $_SERVER[PHP_SELF];?>" method="post"><div class="title">網路速度測試<span><input name="act" type="submit" class="btn" value="開始測試" /></span></div><ul><li style="content:"> <table align="center" width="550" border="0" cellspacing="0" cellpadding="0" > <tr > <td height="15" width="50">頻寬</td><td height="15" width="50">1M</td> <td height="15" width="50">2M</td> <td height="15" width="50">3M</td> <td height="15" width="50">4M</td> <td height="15" width="50">5M</td> <td height="15" width="50">6M</td> <td height="15" width="50">7M</td> <td height="15" width="50">8M</td> <td height="15" width="50">9M</td> <td height="15" width="50">10M</td> </tr> <tr> <td colspan="11" class="suduk" ><table align="center" width="550" border="0" cellspacing="0" cellpadding="0" height="8" class="suduk"> <tr> <td class="sudu" width="<?phpif(preg_match("/[^\d-., ]/",$speed)){echo "0";}else{echo 550*($speed/11000);}?>"></td> <td class="suduk" width="<?phpif(preg_match("/[^\d-., ]/",$speed)){echo "550";}else{echo 550-550*($speed/11000);}?>"></td> </tr> </table> </td> </tr> </table> <?php echo (isset($_GET['speed']))?"下載 1000 KB 資料用時 <b>".$_GET['speed']."</b> 毫秒,下載速度:<b>".$speed." KB/s</b>,需測試多次取平均值,超過10M直接看下載速度": "<em> 未探測 </em>" ?></li></ul></form></div><!--測速結束--><div class="box"><div class="title">已編譯模組監測</div><ul><li><?php echo check_extension(); ?></li></ul></div><!--模組監測結束--><div class="box"><div class="title">組件及資料庫支援監測</div><ul><li><table width="100%" cellpadding="3" cellspacing="0" align="center"> <tr> <td width="32%">FTP支援:</td> <td width="18%"><?php echo isfun("ftp_login");?></td> <td width="32%">XML解析支援:</td> <td width="18%"><?php echo isfun("xml_set_object");?></td> </tr> <tr> <td>Session支援:</td> <td><?php echo isfun("session_start");?></td> <td>Socket支援:</td> <td><?php echo isfun("socket_accept");?></td> </tr> <tr> <td>GD庫支援:</td> <td> <?php if(function_exists(gd_info)) { $gd_info = @gd_info(); echo $gd_info["GD Version"]; }else{echo '<em>×</em>';}?></td> <td>壓縮檔支援(Zlib):</td> <td><?php echo isfun("gzclose");?></td> </tr> <tr> <td>IMAP電子郵件系統函數庫:</td> <td><?php echo isfun("imap_close");?></td> <td>曆法運算函數庫:</td> <td><?php echo isfun("JDToGregorian");?></td> </tr> <tr> <td>Regex函數庫:</td> <td><?php echo isfun("preg_match");?></td> <td>WDDX支援:</td> <td><?php echo isfun("wddx_add_vars");?></td> </tr> <tr> <td>高精度數學運算:</td> <td><?php echo isfun("bcadd");?></td> <td>LDAP目錄協議:</td> <td><?php echo isfun("ldap_close");?></td> </tr> <tr> <td>MCrypt加密處理:</td> <td><?php echo isfun("mcrypt_cbc");?></td> <td>哈稀計算:</td> <td><?php echo isfun("mhash_count");?></td> </tr> <tr> <td>MCrypt加密處理:</td> <td><?php echo isfun("mcrypt_cbc");?></td> <td>哈稀計算:</td> <td><?php echo isfun("mhash_count");?></td> </tr> </table> </li> <li> <table width="100%" cellpadding="3" cellspacing="0" align="center"> <tr> <td width="32%">MySQL 資料庫:</td> <td width="18%"><?php echo isfun("mysql_close");?> <?php if(function_exists("mysql_get_server_info")) { $s = @mysql_get_server_info(); $s = $s ? ' mysql_server 版本:'.$s : ''; $c = ' mysql_client 版本:'.@mysql_get_client_info(); echo $s ? $s : $c; } ?></td> <td width="32%">ODBC 資料庫:</td> <td width="18%"><?php echo isfun("odbc_close");?></td> </tr> <tr> <td>Oracle 資料庫:</td> <td><?php echo isfun("ora_close");?></td> <td>SQL Server 資料庫:</td> <td><?php echo isfun("mssql_close");?></td> </tr> <tr> <td>dBASE 資料庫:</td> <td><?php echo isfun("dbase_close");?></td> <td>mSQL 資料庫:</td> <td><?php echo isfun("msql_close");?></td> </tr> <tr> <td>SQLite 資料庫:</td> <td><?php echo isfun("sqlite_close"); if(isfun("sqlite_close") == '<b>√</b>'){echo " 版本: ".@sqlite_libversion();}?></td> <td>Hyperwave 資料庫:</td> <td><?php echo isfun("hw_close");?></td> </tr></table></li></ul></div><!--組件支援--><div class="box"><div class="title">資料庫連接測試</div><ul><li><?php if(function_exists('mysql_connect')) { ?><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><p>主機:<span><input type="text" name="host" value="127.0.0.1:3306" /></span></p><p>使用者:<span><input type="text" name="user" /></span></p><p>密碼:<span><input type="password" name="pass" /></span></p><p><input type="submit" value="檢測MYSQL" /><?php if(isset($_POST['host']) and isset($_POST['user']) and isset($_POST['pass'])) { echo '<span style="background-color:#663399">'.check_mysql($_POST['host'],$_POST['user'],$_POST['pass']).'</span>'; } ?></p></form><?php } else { echo '<span style="color:#60def0">未找到Mysql擴充!</span>'; } ?></li></ul></div></body></html>
本探針運行如下:
您可直接儲存成phpinfo.php檔案,在PHP環境下測試回合。
總結:
本款代碼還有一個實用的PHP與MYSQL資料庫連接測試模組,HTML5技術的加入,使得本款php探針的介面相當簡潔美觀,希望對你的工作有所協助!
相關推薦:
php探針在Linux下的安裝過程
php探針檢測虛擬機器主機配置資訊的案例
php探針程式的推薦
如何使用php探針環境檢測代碼的樣本
什麼是php探針?php探針有什麼作用?