|
Posted by "Rahul S. Johari" on 11/17/05 17:52
Ave,
Interesting.
I did get this JavaScript code for OS detection:
// This script sets OSName variable as follows:
// "Windows" for all versions of Windows
// "MacOS" for all versions of Macintosh OS
// "Linux" for all versions of Linux
// "UNIX" for all other UNIX flavors
// "Unknown OS" indicates failure to detect the OS
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
document.write('Your OS: '+OSName);
Which does serve my purpose. I guess I'll work something with this out.
Thanks.
On 11/17/05 10:21 AM, "George Pitcher" <george.pitcher@ingenta.com> wrote:
> Rahul,
>
> The Client OS is a 'client' object, so isn't necessarily passed by the
> Browser. Try javascript.
>
> George
>
>> -----Original Message-----
>> From: Rahul S. Johari [mailto:rjohari@nycap.rr.com]
>> Sent: 17 November 2005 3:10 pm
>> To: PHP
>> Subject: [PHP] OS Detection
>>
>>
>>
>> Ave,
>>
>> I'm working on a Guestbook for a site and I'm trying to identify Browser &
>> Operating System of the user and eventually I'll display the Icon matching
>> the Browser/OS in the entry.
>>
>> I'm able to identify and use an If Conditional statement for the Browser,
>> but I can't seem to identify the OS.
>>
>> This is what I'm using to identify the Browser:
>>
>>
>> function browser_detection( $which_test ) {
>>
>> // initialize the variables
>> $browser = '';
>> $dom_browser = '';
>>
>> // set to lower case to avoid errors, check to see if
>> http_user_agent is set
>> $navigator_user_agent = ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) ?
>> strtolower( $_SERVER['HTTP_USER_AGENT'] ) : '';
>>
>> // run through the main browser possibilities, assign them to the main
>> $browser variable
>> if (stristr($navigator_user_agent, "opera"))
>> {
>> $browser = 'opera';
>> $dom_browser = true;
>> }
>>
>> elseif (stristr($navigator_user_agent, "msie 4"))
>> {
>> $browser = 'msie4';
>> $dom_browser = false;
>> }
>>
>> elseif (stristr($navigator_user_agent, "msie"))
>> {
>> $browser = 'msie';
>> $dom_browser = true;
>> }
>>
>> elseif ((stristr($navigator_user_agent, "konqueror")) ||
>> (stristr($navigator_user_agent, "safari")))
>> {
>> $browser = 'safari';
>> $dom_browser = true;
>> }
>>
>> elseif (stristr($navigator_user_agent, "gecko"))
>> {
>> $browser = 'mozilla';
>> $dom_browser = true;
>> }
>>
>> elseif (stristr($navigator_user_agent, "mozilla/4"))
>> {
>> $browser = 'ns4';
>> $dom_browser = false;
>> }
>>
>> else
>> {
>> $dom_browser = false;
>> $browser = false;
>> }
>>
>> // return the test result you want
>> if ( $which_test == 'browser' )
>> {
>> return $browser;
>> }
>> elseif ( $which_test == 'dom' )
>> {
>> return $dom_browser;
>> // note: $dom_browser is a boolean value, true/false, so you can
>> just test
>> if
>> // it's true or not.
>> }
>> }
>>
>> $user_browser = browser_detection('browser');
>>
>> echo "$user_browser";
>>
>> if ( $user_browser == 'opera' )
>> {
>> echo "OPERA";
>> }
>> else {
>> echo "SOMETHING ELSE";
>> }
>>
>> ?>
>>
>> Any suggestions on getting the OS ?
>>
>> Thanks,
>>
>> Rahul S. Johari
>> Coordinator, Internet & Administration
>> Informed Marketing Services Inc.
>> 251 River Street
>> Troy, NY 12180
>>
>> Tel: (518) 266-0909 x154
>> Fax: (518) 266-0909
>> Email: rahul@informed-sources.com
>> http://www.informed-sources.com
>>
>>
>
Rahul S. Johari
Coordinator, Internet & Administration
Informed Marketing Services Inc.
251 River Street
Troy, NY 12180
Tel: (518) 266-0909 x154
Fax: (518) 266-0909
Email: rahul@informed-sources.com
http://www.informed-sources.com
[Back to original message]
|