首页 > 后端开发 > php教程 > PHP语言、浏览器、操作系统、IP、地理位置、ISP,phpisp_PHP教程

PHP语言、浏览器、操作系统、IP、地理位置、ISP,phpisp_PHP教程

WBOY
发布: 2016-07-12 08:58:06
原创
841 人浏览过

PHP语言、浏览器、操作系统、IP、地理位置、ISP,phpisp

<span><?php<br /></span><span>$obj </span><span>= </span><span>new </span><span>class_guest_info</span><span>;<br /></span><span>$obj</span><span>-></span><span>GetLang</span>()<span>; </span><span>//</span><span>获取访客语言:简体中文、繁體中文、</span><span>English</span><span>。<br /></span><span>$obj</span><span>-></span><span>GetBrowser</span>()<span>; </span><span>//</span><span>获取访客浏览器:</span><span>MSIE</span><span>、</span><span>Firefox</span><span>、</span><span>Chrome</span><span>、</span><span>Safari</span><span>、</span><span>Opera</span><span>、</span><span>Other</span><span>。<br /></span><span>$obj</span><span>-></span><span>GetOS</span>()<span>; </span><span>//</span><span>获取访客操作系统:</span><span>Windows</span><span>、</span><span>MAC</span><span>、</span><span>Linux</span><span>、</span><span>Unix</span><span>、</span><span>BSD</span><span>、</span><span>Other</span><span>。<br /></span><span>$obj</span><span>-></span><span>GetIP</span>()<span>; </span><span>//</span><span>获取访客</span><span>IP</span><span>地址。<br /></span><span>$obj</span><span>-></span><span>GetAdd</span>()<span>; </span><span>//</span><span>获取访客地理位置,使用</span><span> Baidu </span><span>隐藏接口。<br /></span><span>$obj</span><span>-></span><span>GetIsp</span>()<span>; </span><span>//</span><span>获取访客</span><span>ISP</span><span>,使用</span><span> Baidu </span><span>隐藏接口。<br /></span><span>class </span><span>class_guest_info<br /></span>{<br />    <span>function </span><span>GetLang</span>()<br />    {<br />        <span>$Lang </span><span>= </span><span>substr</span>(<span>$_SERVER</span><span>[</span><span>'HTTP_ACCEPT_LANGUAGE'</span><span>], </span><span>0</span><span>, </span><span>4</span>)<span>;<br /></span> <span>//</span><span>使用</span><span>substr()</span><span>截取字符串,从</span><span> 0 </span><span>位开始,截取</span><span>4</span><span>个字符<br /></span> <span>if </span>(<span>preg_match</span>(<span>'/zh-c/i'</span><span>, </span><span>$Lang</span>)) {<br />            <span>//preg_match()</span><span>正则表达式匹配函数<br /></span> <span>$Lang </span><span>= </span><span>'</span><span>简体中文</span><span>'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/zh/i'</span><span>, </span><span>$Lang</span>)) {<br />            <span>$Lang </span><span>= </span><span>'</span><span>繁體中文</span><span>'</span><span>;<br /></span> } <span>else </span>{<br />            <span>$Lang </span><span>= </span><span>'English'</span><span>;<br /></span> }<br />        <span>return </span><span>$Lang</span><span>;<br /></span> }<br /><br />    <span>function </span><span>GetBrowser</span>()<br />    {<br />        <span>$Browser </span><span>= </span><span>$_SERVER</span><span>[</span><span>'HTTP_USER_AGENT'</span><span>];<br /></span> <span>if </span>(<span>preg_match</span>(<span>'/MSIE/i'</span><span>, </span><span>$Browser</span>)) {<br />            <span>$Browser </span><span>= </span><span>'MSIE'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/Firefox/i'</span><span>, </span><span>$Browser</span>)) {<br />            <span>$Browser </span><span>= </span><span>'Firefox'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/Chrome/i'</span><span>, </span><span>$Browser</span>)) {<br />            <span>$Browser </span><span>= </span><span>'Chrome'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/Safari/i'</span><span>, </span><span>$Browser</span>)) {<br />            <span>$Browser </span><span>= </span><span>'Safari'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/Opera/i'</span><span>, </span><span>$Browser</span>)) {<br />            <span>$Browser </span><span>= </span><span>'Opera'</span><span>;<br /></span> } <span>else </span>{<br />            <span>$Browser </span><span>= </span><span>'Other'</span><span>;<br /></span> }<br />        <span>return </span><span>$Browser</span><span>;<br /></span> }<br /><br />    <span>function </span><span>GetOS</span>()<br />    {<br />        <span>$OS </span><span>= </span><span>$_SERVER</span><span>[</span><span>'HTTP_USER_AGENT'</span><span>];<br /></span> <span>if </span>(<span>preg_match</span>(<span>'/win/i'</span><span>, </span><span>$OS</span>)) {<br />            <span>$OS </span><span>= </span><span>'Windows'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/mac/i'</span><span>, </span><span>$OS</span>)) {<br />            <span>$OS </span><span>= </span><span>'MAC'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/linux/i'</span><span>, </span><span>$OS</span>)) {<br />            <span>$OS </span><span>= </span><span>'Linux'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/unix/i'</span><span>, </span><span>$OS</span>)) {<br />            <span>$OS </span><span>= </span><span>'Unix'</span><span>;<br /></span> } <span>elseif </span>(<span>preg_match</span>(<span>'/bsd/i'</span><span>, </span><span>$OS</span>)) {<br />            <span>$OS </span><span>= </span><span>'BSD'</span><span>;<br /></span> } <span>else </span>{<br />            <span>$OS </span><span>= </span><span>'Other'</span><span>;<br /></span> }<br />        <span>return </span><span>$OS</span><span>;<br /></span> }<br /><br />    <span>function </span><span>GetIP</span>()<br />    {<br />        <span>if </span>(<span>!</span><span>emptyempty</span>(<span>$_SERVER</span><span>[</span><span>'HTTP_CLIENT_IP'</span><span>]</span>)) {<br />            <span>//</span><span>如果变量是非空或非零的值,则</span><span> empty()</span><span>返回</span><span> FALSE</span><span>。<br /></span> <span>$IP </span><span>= </span><span>explode</span>(<span>','</span><span>, </span><span>$_SERVER</span><span>[</span><span>'HTTP_CLIENT_IP'</span><span>]</span>)<span>;<br /></span> } <span>elseif </span>(<span>!</span><span>emptyempty</span>(<span>$_SERVER</span><span>[</span><span>'HTTP_X_FORWARDED_FOR'</span><span>]</span>)) {<br />            <span>$IP </span><span>= </span><span>explode</span>(<span>','</span><span>, </span><span>$_SERVER</span><span>[</span><span>'HTTP_X_FORWARDED_FOR'</span><span>]</span>)<span>;<br /></span> } <span>elseif </span>(<span>!</span><span>emptyempty</span>(<span>$_SERVER</span><span>[</span><span>'REMOTE_ADDR'</span><span>]</span>)) {<br />            <span>$IP </span><span>= </span><span>explode</span>(<span>','</span><span>, </span><span>$_SERVER</span><span>[</span><span>'REMOTE_ADDR'</span><span>]</span>)<span>;<br /></span> } <span>else </span>{<br />            <span>$IP</span><span>[</span><span>0</span><span>] </span><span>= </span><span>'None'</span><span>;<br /></span> }<br />        <span>return </span><span>$IP</span><span>[</span><span>0</span><span>];<br /></span> }<br /><br />    <span>private function </span><span>GetAddIsp</span>()<br />    {<br />        <span>$IP </span><span>= </span><span>$this</span><span>-></span><span>GetIP</span>()<span>;<br /></span> <span>$AddIsp </span><span>= </span><span>mb_convert_encoding</span>(<span>file_get_contents</span>(<span>'http://open.baidu.com/ipsearch/stn=ipjson&wd=' </span><span>. </span><span>$IP</span>)<span>, </span><span>'UTF-8'</span><span>, </span><span>'GBK'</span>)<span>;<br /></span> <span>//mb_convert_encoding() </span><span>转换字符编码。<br /></span> <span>if </span>(<span>preg_match</span>(<span>'/noresult/i'</span><span>, </span><span>$AddIsp</span>)) {<br />            <span>$AddIsp </span><span>= </span><span>'None'</span><span>;<br /></span> } <span>else </span>{<br />            <span>$Sta </span><span>= </span><span>stripos</span>(<span>$AddIsp</span><span>, </span><span>$IP</span>) <span>+ </span><span>strlen</span>(<span>$IP</span>) <span>+ </span><span>strlen</span>(<span>'</span><span>来自</span><span>'</span>)<span>;<br /></span> <span>$Len </span><span>= </span><span>stripos</span>(<span>$AddIsp</span><span>, </span><span>'"}'</span>) <span>- </span><span>$Sta</span><span>;<br /></span> <span>$AddIsp </span><span>= </span><span>substr</span>(<span>$AddIsp</span><span>, </span><span>$Sta</span><span>, </span><span>$Len</span>)<span>;<br /></span> }<br />        <span>$AddIsp </span><span>= </span><span>explode</span>(<span>' '</span><span>, </span><span>$AddIsp</span>)<span>;<br /></span> <span>return </span><span>$AddIsp</span><span>;<br /></span> }<br /><br />    <span>function </span><span>GetAdd</span>()<br />    {<br />        <span>$Add </span><span>= </span><span>$this</span><span>-></span><span>GetAddIsp</span>()<span>;<br /></span> <span>return </span><span>$Add</span><span>[</span><span>0</span><span>];<br /></span> }<br /><br />    <span>function </span><span>GetIsp</span>()<br />    {<br />        <span>$Isp </span><span>= </span><span>$this</span><span>-></span><span>GetAddIsp</span>()<span>;<br /></span> <span>if </span>(<span>$Isp</span><span>[</span><span>0</span><span>] </span><span>!= </span><span>'None' </span><span>&& </span><span>isset</span>(<span>$Isp</span><span>[</span><span>1</span><span>]</span>)) {<br />            <span>$Isp </span><span>= </span><span>$Isp</span><span>[</span><span>1</span><span>];<br /></span> } <span>else </span>{<br />            <span>$Isp </span><span>= </span><span>'None'</span><span>;<br /></span> }<br />        <span>return </span><span>$Isp</span><span>;<br /></span> }<br />}<br /><br />
登录后复制

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/1105143.htmlTechArticlePHP语言、浏览器、操作系统、IP、地理位置、ISP,phpisp ?php $obj = new class_guest_info ; $obj - GetLang () ; // 获取访客语言:简体中文、繁體中文、...
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板