tags:

views:

248

answers:

4

Is there a simplistic solution to obtain the version of Java running on a user's workstation using php? Basically I want to know the version of Java running on a user's machine who accesses my portal. This data will help me make some policy decisions later since our product is Java based.

A: 

Their client would need to send you this information explicitly. If they are accessing your site via a web browser, that is not the sort of thing that's going to show up in a user agent string.

On the other hand, if they are programmatically accessing your site with Java code, then it will show up in the user agent string. But given your statement about a product, I'd tend to think this is just a normal website intended for browser access.

danben
Any comments from the downmodder? Perhaps you disagree?
danben
A: 

The browser_get() function will try to tell you if execution of Java applets is available.

With PHP alone I believe this is your best bet.

Alix Axel
Although this will not give me the exact Java version...
Chantz
As I said, you can't get that with PHP alone - that was your question, wasn't it?
Alix Axel
+1  A: 

Check javatester.org they use a little applet to get the running JVM version. You can modify it to push the result to your server.

Mauricio
+4  A: 

The only client side languages which have (in)direct access to both client side (to determine the information) and server side (to send the information) are JavaScript and ActionScript.

I think you're as being a PHP programmer already less or more familiar with JavaScript, so I would go ahead with that. Fortunately Sun already offers the Java Deployment Toolkit JavaScript library exactly for those needs. Here's an SSCCE, just copy'n'paste'n'run it:

<!doctype html>
<html lang="en">
    <head>
        <title>SO question 2111383</title>
        <script type="text/javascript" src="http://java.com/js/deployJava.js"&gt;&lt;/script&gt;
        <script type="text/javascript">
            alert(deployJava.getJREs()); // Show all installed JRE versions.
        </script>
    </head>
    <body>
        <h1>That's all, Folks!</h1>
    </body>
</html>

Once having the information, just send it to the server side. You can do that either synchronously by passing it as a hidden input element of a form, or asynchronously using Ajaxical techniques. jQuery is perfectly suitable for this. Just do a $.get('script.php?java=' + deployJava.getJREs()); or so.

BalusC
@Downvoter: Care to explain? Is it just ignorance? :o
BalusC
+1 to counter-act.
Alix Axel
+1 nice proof that Js can be used to get JRE info.
Samuel Sjöberg
Thanks. This Works.
Chantz
You're welcome.
BalusC