Skip to content

Instantly share code, notes, and snippets.

@xfoxfu
Last active October 1, 2015 01:11
Show Gist options
  • Save xfoxfu/9248858 to your computer and use it in GitHub Desktop.
Save xfoxfu/9248858 to your computer and use it in GitHub Desktop.
Anti XP PHP Script ( Without Need of `browscap.ini` )
<?php
/**
* Anti-XP Script
*
* @author 小傅Fox[<[email protected]>]
*/
/**
* 获得客户端的操作系统
* Source:{@link http://lok.me/a/1027.html}
*
* @access private
* @return
*
*
*
*/
function get_os()
{
if( empty( $_SERVER[ 'HTTP_USER_AGENT' ] ) ){
return 'Unknown';
}
$agent = strtolower( $_SERVER[ 'HTTP_USER_AGENT' ] );
$os = '';
if( strpos( $agent , 'win' ) !== false ){
if( strpos( $agent , 'nt 5.1' ) !== false ){
$os = 'Windows XP';
} elseif( strpos( $agent , 'nt 5.2' ) !== false ){
$os = 'Windows 2003';
} elseif( strpos( $agent , 'nt 5.0' ) !== false ){
$os = 'Windows 2000';
} elseif( strpos( $agent , 'nt 6.0' ) !== false ){
$os = 'Windows Vista';
} elseif( strpos( $agent , 'nt 6.1' ) !== false ){
$os = 'Windows 7';
} elseif( strpos( $agent , 'nt 6.2' ) !== false ){
$os = 'Windows 8';
} elseif( strpos( $agent , 'nt' ) !== false ){
$os = 'Windows NT';
} elseif( strpos( $agent , 'win 9x' ) !== false && strpos( $agent , '4.90' ) !== false ){
$os = 'Windows ME';
} elseif( strpos( $agent , '98' ) !== false ){
$os = 'Windows 98';
} elseif( strpos( $agent , '95' ) !== false ){
$os = 'Windows 95';
} elseif( strpos( $agent , '32' ) !== false ){
$os = 'Windows 32';
} elseif( strpos( $agent , 'ce' ) !== false ){
$os = 'Windows CE';
}
} elseif( strpos( $agent , 'linux' ) !== false ){
$os = 'Linux';
} elseif( strpos( $agent , 'unix' ) !== false ){
$os = 'Unix';
} elseif( strpos( $agent , 'sun' ) !== false && strpos( $agent , 'os' ) !== false ){
$os = 'SunOS';
} elseif( strpos( $agent , 'ibm' ) !== false && strpos( $agent , 'os' ) !== false ){
$os = 'IBM OS/2';
} elseif( strpos( $agent , 'mac' ) !== false && strpos( $agent , 'pc' ) !== false ){
$os = 'Macintosh';
} elseif( strpos( $agent , 'powerpc' ) !== false ){
$os = 'PowerPC';
} elseif( strpos( $agent , 'aix' ) !== false ){
$os = 'AIX';
} elseif( strpos( $agent , 'hpux' ) !== false ){
$os = 'HPUX';
} elseif( strpos( $agent , 'netbsd' ) !== false ){
$os = 'NetBSD';
} elseif( strpos( $agent , 'bsd' ) !== false ){
$os = 'BSD';
} elseif( strpos( $agent , 'osf1' ) !== false ){
$os = 'OSF1';
} elseif( strpos( $agent , 'irix' ) !== false ){
$os = 'IRIX';
} elseif( strpos( $agent , 'freebsd' ) !== false ){
$os = 'FreeBSD';
} elseif( strpos( $agent , 'teleport' ) !== false ){
$os = 'teleport';
} elseif( strpos( $agent , 'flashget' ) !== false ){
$os = 'flashget';
} elseif( strpos( $agent , 'webzip' ) !== false ){
$os = 'webzip';
} elseif( strpos( $agent , 'offline' ) !== false ){
$os = 'offline';
} else{
$os = 'Unknown';
}
return $os;
}
if( get_os() == 'Windows XP' ){
if( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] == 'zh-CN' ){
die( '你仍然在使用落后的Windows XP操作系统,在你升级操作系统前将不能打开此页面。识别的OS为:' . get_os() );
} elseif( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] == 'zh-TW' ){
die( '你仍然在使用落後的Windows XP作業系統,在你升級作業系統前將不能開啟此頁面。識別的OS為:' . get_os() );
} elseif( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] == 'zh-HK' ){
die( '你仍然在使用落後的Windows XP作業系統,在你升級作業系統前將不能開啟此頁面。識別的OS爲:' . get_os() );
} elseif( $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] == 'en-US' || $_SERVER[ 'HTTP_ACCEPT_LANGUAGE' ] == 'en' ){
die( 'You are STILL using Windows XP! We no longer offer services to you unless you upgrade your OS! Your OS is recognized as ' . get_os() );
}
}
@m13253
Copy link

m13253 commented Feb 27, 2014

英语句子之间最好再加一个空格。

You are STILL using Windows XP! We no longer offer services to you unless you upgrade your OS! Your OS is recognized as xxx

@m13253
Copy link

m13253 commented Feb 27, 2014

@xfoxfu
Copy link
Author

xfoxfu commented Feb 28, 2014

@m13253 Merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment