Home  >  Article  >  php教程  >  php获取系统信息的方法

php获取系统信息的方法

WBOY
WBOYOriginal
2016-06-13 11:30:31804browse


用 getenv函数进行处理:

<?<span php
</span><span $root</span> = <span getenv</span>('DOCUMENT_ROOT'); <span //</span><span //服务器文档根目录</span>
<span $port</span> = <span getenv</span>('SERVER_PORT'); <span //</span><span //服务器端口</span>
<span $file</span> = <span getenv</span>('SCRIPT_NAME'); <span //</span><span //当前执行文件</span>
<span $ua</span> = <span getenv</span>('HTTP_USER_AGENT'); <span //</span><span //用户UA</span>
<span $method</span> = <span getenv</span>('REQUEST_METHOD'); <span //</span><span //请求方法</span>
<span $protocol</span> = <span getenv</span>('SERVER_PROTOCOL'); <span //</span><span //传输协议</span>
<span getmypid</span>(), <span //</span><span //返回当前PHP进程的进程ID号,该函数不需要输入参数。</span>
<span get_current_user</span>(), <span //</span><span //返回当前程序的所有者名称,该函数也不需要输入参数。</span>
?>

示例:

<?<span php
</span><span /*</span><span *
* php获取系统信息
* by www.jbxue.com
</span><span */</span><span 
获取系统类型及版本号: </span><span php_uname</span>() (例:Windows NT COMPUTER 5.1 build 2600<span )

只获取系统类型: </span><span php_uname</span>('s') (或:<span PHP_OS</span><span ,例:Windows NT)
只获取系统版本号: </span><span php_uname</span>('r') (例:5.1<span )
获取PHP运行方式: </span><span php_sapi_name</span><span () (PHP run mode:apache2handler)
获取前进程用户名: </span><span Get_Current_User</span><span ()
获取PHP版本: </span><span PHP_VERSION</span><span 
获取Zend版本: </span><span Zend_Version</span><span ()
获取PHP安装路径: </span><span DEFAULT_INCLUDE_PATH</span><span 
获取当前文件绝对路径: </span><span __FILE__</span><span 
获取Http请求中Host值: </span><span $_SERVER</span>["HTTP_HOST"<span ] (返回值为域名或IP)
获取服务器IP: </span><span GetHostByName</span>(<span $_SERVER</span>['SERVER_NAME'<span ])
接受请求的服务器IP: </span><span $_SERVER</span>["SERVER_ADDR"] (有时候获取不到,推荐用:<span GetHostByName</span>(<span $_SERVER</span>['SERVER_NAME'<span ]))
获取客户端IP: </span><span $_SERVER</span>['REMOTE_ADDR'<span ]
获取服务器解译引擎: </span><span $_SERVER</span>['SERVER_SOFTWARE'<span ]
获取服务器CPU数量: </span><span $_SERVER</span>['PROCESSOR_IDENTIFIER'<span ]
获取服务器系统目录: </span><span $_SERVER</span>['SystemRoot'<span ]
获取服务器域名: </span><span $_SERVER</span>['SERVER_NAME'] (建议使用:<span $_SERVER</span>["HTTP_HOST"<span ])
获取用户域名: </span><span $_SERVER</span>['USERDOMAIN'<span ]
获取服务器语言: </span><span $_SERVER</span>['HTTP_ACCEPT_LANGUAGE'<span ]
获取服务器Web端口: </span><span $_SERVER</span>['SERVER_PORT'<span ]
</span>?>
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
Previous article:Eclipse字符集设置方式Next article:开始yaf之旅