PHP get browser client operating system IP address class

Source: Internet
Author: User
Tags ereg get ip

Class client{

Public Function __construct ()
{
/**/
}

/**
* Get Browser client
*
* @return String
*/
Public Function Browser ()
{
$info = $_server[' http_user_agent '];
if (Strstr ($info, ' MSIE 6.0 ')!= false) {
Return ' IE6 ';
}elseif (Strstr ($info, ' MSIE 7.0 ')!= false) {
Return ' IE7 ';
}elseif (Strstr ($info, ' Firefox ')!= false) {
Return ' Firefox ';
}elseif (Strstr ($info, ' Chrome ')!= false) {
Return ' Chrome ';
}elseif (Strstr ($info, ' Safari ')!= false) {
Return ' Safari ';
}else{
Return ' Unknow ';
}
}

/**
* Get the operating system
* @return String
*/
Public Function Getos ()
{
$agent = $_server[' http_user_agent '];
$os = false;
if (eregi (' win ', $agent) && strpos ($agent, ' 95 ')) {
$os = ' Windows 95 ';
}
else if (eregi (' Win 9x ', $agent) && strpos ($agent, ' 4.90 ')) {
$os = ' Windows ME ';
}
else if (eregi (' win ', $agent) && ereg (' $agent) ') {
$os = ' Windows 98 ';
}
else if (eregi (' win ', $agent) && eregi (' NT 5.1 ', $agent)) {
$os = ' Windows XP ';
}
else if (eregi (' win ', $agent) && eregi (' NT 5 ', $agent)) {
$os = ' Windows 2000 ';
}
else if (eregi (' win ', $agent) && eregi (' NT ', $agent)) {
$os = ' Windows NT ';
}
else if (eregi (' win ', $agent) && ereg (' A ', $agent)) {
$os = ' Windows 32 ';
}
else if (eregi (' Linux ', $agent)) {
$os = ' Linux ';
}
else if (eregi (' Unix ', $agent)) {
$os = ' Unix ';
}
else if (eregi (' Sun ', $agent) && eregi (' OS ', $agent)) {
$os = ' SunOS ';
}
else if (eregi (' IBM ', $agent) && eregi (' OS ', $agent)) {
$os = ' IBM os/2 ';
}
else if (eregi (' Mac ', $agent) && eregi (' PC ', $agent)) {
$os = ' Macintosh ';
}
else if (eregi (' PowerPC ', $agent)) {
$os = ' PowerPC ';
}
else if (eregi (' AIX ', $agent)) {
$os = ' AIX ';
}
else if (eregi (' HPUX ', $agent)) {
$os = ' HPUX ';
}
else if (eregi (' NetBSD ', $agent)) {
$os = ' NetBSD ';
}
else if (eregi (' BSD ', $agent)) {
$os = ' BSD ';
}
else if (ereg (' OSF1 ', $agent)) {
$os = ' OSF1 ';
}
else if (ereg (' IRIX ', $agent)) {
$os = ' IRIX ';
}
else if (eregi (' FreeBSD ', $agent)) {
$os = ' FreeBSD ';
}
else if (eregi (' teleport ', $agent)) {
$os = ' teleport ';
}
else if (eregi (' FlashGet ', $agent)) {
$os = ' FlashGet ';
}
else if (eregi (' Webzip ', $agent)) {
$os = ' Webzip ';
}
else if (eregi (' Offline ', $agent)) {
$os = ' offline ';
}
else {
$os = ' Unknown ';
}
return $os;
}

/**
* Get IP Address
* @return String
*/
Public Function GetIP ()
{
if (getenv ("Http_client_ip") && strcasecmp (getenv ("Http_client_ip"), "Unknown")) {
$ip = getenv ("Http_client_ip");
}elseif (getenv ("Http_x_forwarded_for") && strcasecmp (getenv ("Http_x_forwarded_for"), "Unknown")) {
$ip = getenv ("Http_x_forwarded_for");
}elseif (getenv ("REMOTE_ADDR") && strcasecmp (getenv ("REMOTE_ADDR"), "Unknown")) {
$ip = getenv ("REMOTE_ADDR");
}elseif (Isset ($_server[' remote_addr ']) && $_server[' remote_addr '] && strcasecmp ($_server[' Remote_ ADDR '], "unknown") {
$ip = $_server[' remote_addr '];
}else{
$ip = "Unknown";
}
return ($IP);
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.