欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

phpnow php探针环境检测代码

程序员文章站 2022-05-30 08:36:56
<?php
/*
 http://phpnow.org
 yinzcn_at_gmail.com
*/

error_reporting(e_all);

define('timezone', +8.0);

function _get($n) { return isset($_get[$n]) ? $_get[$n] : null; }
function _server($n) { return isset($_server[$n]) ? $_server[$n] : '[undefine]'; }

if (_get('act') == 'phpinfo') {
 if (function_exists('phpinfo')) phpinfo();
 else echo 'phpinfo() has been disabled.';
 exit;
}

$info = array();
$info['php_ini_file'] = function_exists('php_ini_loaded_file') ? php_ini_loaded_file() : '[undefine]';

if (_get('act') == 'getip') {
 $i = _server('server_name').'|'._server('remote_addr').'|'._server('server_software').'|'.(function_exists('mysql_close')?mysql_get_client_info():'').'|'._server('document_root');
 $c = @file_get_contents('http://phpnow.org/myip.php?'.base64_encode($i));
 if (preg_match('/^\d+\.\d+\.\d+\.\d+$/', $c) == 1) echo $c;
 else echo 'false';
 exit;
}

function colorhost() {
 $c = array('#87cefa', '#ffa500', '#ff6347', '#9acd32', '#32cd32', '#ee82ee');
 $a = str_split(_server('server_name'));
 $k = $l = 0;
 foreach ($a as &$d) {
  while ($k==$l) $k = array_rand($c);
  $d = '<b style="color: '.$c[$k].';">'.$d.'</b>';
  $l = $k;
 }
 return implode('', $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('yes', '<span style="color: #008000; font-weight : bold;">yes</span>');
define('no', '<span style="color: #ff0000; font-weight : bold;">no</span>');
?>
<!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 == 'false') $('ip_r').innerhtml = '获取外网 ip 失败!';
   else $('ip_r').innerhtml = '此服务器互联网 ip<br /><a href="http://'+r+'" style="color: #999999;">'+r+'</a>';
  }
 }
 xmlhttp.open("get", "?act=getip", true);
 xmlhttp.send();
}
</script>
</head>
<body onload="get_ip();">
<div style="margin: 0 auto; width: 600px;">

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

 <div style="float: left;">
  <div style="font-weight: bold; font-size: 2.2em;"><a href="<?=_server('php_self')?>?" style="text-decoration: none;"><?=colorhost()?></a></div>
  <div style="margin: 5px auto;"># let's <b style="color: #777bb4;">php</b> <b style="color: #ff4500;">now</b> <b>!</b></div>
 </div>
</div>

<br />

<table width="100%" class="info">
 <tr>
  <th colspan="2">server information</th>
 </tr>

 <tr>
  <td class="item">server_name</td>
  <td><?=_server('server_name')?></td>
 </tr>

 <tr>
  <td class="item">server_addr:port</td>
  <td><?=_server('server_addr').':'._server('server_port')?></td>
 </tr>

 <tr>
  <td class="item">server_software</td>
  <td><?=stripos(_server('server_software'), 'php')?_server('server_software'):_server('server_software').' php/'.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['php_ini_file']?></td>
 </tr>

 <tr>
  <td class="item">网站主目录</td>
  <td><?=_server('document_root')?></td>
 </tr>

 <tr>
  <td class="item">server date / time</td>
  <td><?=gmdate('y-m-d', time()+timezone*3600)?> <?=gmdate('h:i:s', time()+timezone*3600)?> <span style="color: #999999;">(<?=(timezone<0?'-':'+').gmdate('h:i', abs(timezone)*3600)?>)</span></td>
 </tr>

 <tr>
  <td class="item">other links</td>
  <td>
  <a href='<?=_server('php_self')?>?act=phpinfo'>phpinfo()</a>
  | <?=file_exists('phpmyadmin') ? '<a href="/phpmyadmin">phpmyadmin</a>' : '<a href="http://phpnow.org">phpnow.org</a>'?>
  </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('optimizer_version') ? yes.' / '.optimizer_version : no?></td>
 </tr>

 <tr>
  <td class="item">mysql 支持</td>
  <td><?=function_exists('mysql_close') ? yes.' / client lib version '.mysql_get_client_info() : no?></td>
 </tr>

 <tr>
  <td class="item">gd library</td>
  <td><?=function_exists('gd_info') ? yes.' / '.get_gd_info('gd version') : no?></td>
 </tr>

 <tr>
  <td class="item">eaccelerator</td>
  <td><?=function_exists('eaccelerator_info') ? yes.' / '.get_ea_info('version') : no?></td>
 </tr>
</table>

<hr />

<form method="post" action="<?=_server('php_self')?>">
<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['act'])) {?>
<br />

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

<?php
$link = @mysql_connect($_post['mysqlhost'], $_post['mysqluser'], $_post['mysqlpassword']);
$errno = mysql_errno();
if ($link) $str1 = '<span style="color: #008000; font-weight: bold;">ok</span> ('.mysql_get_server_info($link).')';
else $str1 = '<span style="color: #ff0000; font-weight: bold;">failed</span><br />'.mysql_error();
?>
 <tr>
  <td colspan="2">服务器 <?=$_post['mysqlhost']?></td>
  <td colspan="2"><?=$str1?></td>
 </tr>

 <tr>
  <td colspan="2">数据库 <?=$_post['mysqldb']?></td>
  <td colspan="2"><?=(@mysql_select_db($_post['mysqldb'],$link))?'<span style="color: #008000; font-weight: bold;">ok</span>':'<span style="color: #ff0000; font-weight: bold;">failed</span>'?></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>

</div>
</body>
</html>

上一篇: 你喜欢吃消夜吗

下一篇: 离魂记