how to check PC system of a visitor?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aaaphp000000
Forum Newbie
Posts: 22
Joined: Mon Aug 29, 2005 5:39 am

how to check PC system of a visitor?

Post by aaaphp000000 »

i need to do following process:

IF system is Windows, display a C++ COM control
ELSE
IF JRE is installed on the system, display a APPLET
ELSE
display error message

are there php functios which can help me to check and implement above process?

thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Windows detection, yes, JRE nope.

the user agent string will contain what OS the browser is running (most often) ... the data is unreliable however.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

The first part is quite easy :)

Code: Select all

<?php

if (strpos(PHP_OS, "WIN") !== false) {

    /* enter code for displaying COM panel */

}

?>
The second part I would guess you'll need a JavaScript function to make the check, as I doubt the User Agent (browser) broadcasts that kind of information to the server (remember, PHP is server side and entirely depends upon the information the User Agent sends to the server)

:)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Jenk, your code would detect if the server is a Windows machine... not the client ;)
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

yeah and using double negatives is bad programming technique imo.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Dammit, I quickly copied and pasted from one of my own classes not thinking about it.

And using double negatives is NOT bad practice when challenging such criteria. Read up on PHP.net. :)

Fixed code:

Code: Select all

<?php

if (stripos('Win', $_SERVER['HTTP_USERAGENT']) !== false) {

    /* do com bits */

}
?>
Post Reply