Home > Backend Development > PHP Tutorial > Get the operating system

Get the operating system

WBOY
Release: 2016-07-25 09:01:27
Original
880 people have browsed it
  1. //操作系统
  2. public function getOS(){
  3. $agent = $_SERVER['HTTP_USER_AGENT'];
  4. $os = false;
  5. if (eregi('win', $agent) && strpos($agent, '95'))
  6. $os = 'Windows 95';
  7. else if (eregi('win 9x', $agent) && strpos($agent, '4.90'))
  8. $os = 'Windows ME';
  9. else if (eregi('win', $agent) && ereg('98', $agent))
  10. $os = 'Windows 98';
  11. else if (eregi('win', $agent) && eregi('nt 5.1', $agent))
  12. $os = 'Windows XP';
  13. else if (eregi('win', $agent) && eregi('nt 5', $agent))
  14. $os = 'Windows 2000';
  15. else if (eregi('win', $agent) && eregi('nt 6.1', $agent))
  16. $os = 'Windows 7';
  17. else if (eregi('win', $agent) && eregi('nt 6', $agent))
  18. $os = 'Windows Visita';
  19. else if (eregi('win', $agent) && eregi('nt', $agent))
  20. $os = 'Windows NT';
  21. else if (eregi('win', $agent) && ereg('32', $agent))
  22. $os = 'Windows 32';
  23. else if (eregi('linux', $agent))
  24. $os = 'Linux';
  25. else if (eregi('unix', $agent))
  26. $os = 'Unix';
  27. else if (eregi('sun', $agent) && eregi('os', $agent))
  28. $os = 'SunOS';
  29. else if (eregi('ibm', $agent) && eregi('os', $agent))
  30. $os = 'IBM OS/2';
  31. else if (eregi('Mac', $agent) && eregi('PC', $agent))
  32. $os = 'Macintosh';
  33. else if (eregi('PowerPC', $agent))
  34. $os = 'PowerPC';
  35. else if (eregi('AIX', $agent))
  36. $os = 'AIX';
  37. else if (eregi('HPUX', $agent))
  38. $os = 'HPUX';
  39. else if (eregi('NetBSD', $agent))
  40. $os = 'NetBSD';
  41. else if (eregi('BSD', $agent))
  42. $os = 'BSD';
  43. else if (ereg('OSF1', $agent))
  44. $os = 'OSF1';
  45. else if (ereg('IRIX', $agent))
  46. $os = 'IRIX';
  47. else if (eregi('FreeBSD', $agent))
  48. $os = 'FreeBSD';
  49. else if (eregi('teleport', $agent))
  50. $os = 'teleport';
  51. else if (eregi('flashget', $agent))
  52. $os = 'flashget';
  53. else if (eregi('webzip', $agent))
  54. $os = 'webzip';
  55. else if (eregi('offline', $agent))
  56. $os = 'offline';
  57. else
  58. $os = 'Unknown';
  59. return $os;
  60. }
复制代码


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template