How to check website viewer's operating system?

China☆狼群 提交于 2019-12-05 09:40:44

Can I Imitate Another Browser/Platform?

There are many ways to spoof user agent strings. In firefox, there happens to be an extension called "User Agent Switcher," which allows you to imitate other browsers.

https://addons.mozilla.org/en-US/firefox/addon/59

User Agents

Checking the user-agent often times can tell you this. For instance, my user-agent is:

Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.38 Safari/532.0

Which platform am I on?

Javascript Option

You can also use the navigator object in Javascript to get some information too. For instance:

alert(navigator.platform);  // alerts Win32
alert(navigator.userAgent); // Mozilla/5.0 (Windows; U; Windows NT 6.0...

PHP Options

You can get the user-agent in PHP from the $_SERVER array:

print $_SERVER["HTTP_USER_AGENT"]; // Mozilla/5.0 (Windows; U; Windows NT...

PHP also has further goodies, such as the get_browser()* function in PHP which returns an array of information, including the platform:

Array
(
    ...
    [parent] => Firefox 0.9
    [platform] => WinXP
    [browser] => Firefox
    [version] => 0.9
    ...
)

* get_browser() relies upon browscap.ini - See
http://www.php.net...php#ini.browscap for more information.

How does the website know which OS I'm running? Is it only via javascript or is there OS information in the request headers as well?

That info goes in the User-Agent HTTP header each time you make a request to any server.

Is there a way for me to bypass this check or "pretend" to be using Windows so that I can access the website even though I'm running an unsupported OS?

Check this link for more info in User-Agent spoofing using firefox.

You can use navigator.platform in JavaScript:

var OS = navigator.platform;
alert(OS);

That way you don't have to worry about parsing the user agent.

It may be guessing from the User-Agent string.

Here is the full code. Might help someone, it detects which OS user is using and version, but it doesnt go that deep in versions such as Window 7 home/professional/ultimate etc, that one is way more complex.

//OS DETECTION... 
function find_os(){ 
var OSVer=""; 
if (navigator.userAgent.indexOf("Mac OS X 10.4")!=-1) OSVer="MacOS Tiger"; 
if (navigator.userAgent.indexOf("Mac OS X 10.5")!=-1) OSVer="MacOS Leopard"; 
if (navigator.userAgent.indexOf("Mac OS X 10.6")!=-1) OSVer="MacOS Snow Leopard"; 
if (navigator.userAgent.indexOf("NT 5.1")!=-1) OSVer="Windows XP"; 
if (navigator.userAgent.indexOf("NT 6.0")!=-1) OSVer="Windows Vista"; 
if (navigator.userAgent.indexOf("NT 6.1")!=-1) OSVer="Windows 7"; 
if (navigator.userAgent.indexOf("Linux")!=-1) OSVer="Linux"; 
if (navigator.userAgent.indexOf("X11")!=-1) OSVer="UNIX"; 

returh OSVer; 
}
Mark

The server-side script will present information to the web browser which indicates the user's browser type and version as well as operating system. For example, in PHP you have get_browser()

Opera browser has a facility to Spoof and can present itself as another browser type to avoid browser blocking.

The User Agent Switcher firefox add-on enables "spoofing" of a different web browser.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!