tags:

views:

41

answers:

3

Hi ,

i have two pages redirection in my index.php ,

the page are exmple_system_os.php , example_mobile_os.php

How to determine user operating system in php,

Thanks

+1  A: 

You could parse the $_SERVER['HTTP_USER_AGENT'] string for the various platform details, but I wouldn't be confident that this was a deterministic approach, since it can easily be faked.

David Grant
or does not exist, e.g. when accessed via CLI
Gordon
+3  A: 

The get_browser function can be used to extract a couple of information the User-Agent HTTP header sent by the browser.

Amongst those informations, it seems there is some data about the operating system the browser's running on -- i.e. about the client OS.


Quoting the example given on the manual page of get_browser :

Array
(
    [browser_name_regex] => ^mozilla/5\.0 (windows; .; windows nt 5\.1; .*rv:.*) gecko/.* firefox/0\.9.*$
    [browser_name_pattern] => Mozilla/5.0 (Windows; ?; Windows NT 5.1; *rv:*) Gecko/* Firefox/0.9*
    [parent] => Firefox 0.9
    [platform] => WinXP
    [browser] => Firefox
    [version] => 0.9


But note that the User-Agent HTTP header is sent by the client, which means :

  • It can be disabled
  • It can be faked (i.e. you can get any kind of garbage in it ^^ )
Pascal MARTIN
i run this get browser function , i find one array that is ismobiledevice , ut in my system it is just showing empty array...
Bharanikumar
i thing in my mobile device it showing the 1shall i use , something like when this array is one then redirect page to example_mobile_os.php
Bharanikumar
A: 

problem fixed, i hve used the get_browser funcion,

Bharanikumar