简体   繁体   中英

How to get user's Java version using PHP?

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.

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"></script>
        <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.

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.

If Java is running, simply call a script placed on the server, User-Agent should give you the exact version of the runtime environment . Since the deployment toolkits javascript-code does only list maybe up to 17 released versions for Java 6 ... and earlier, you would have to guess what is the one used by the specific browser.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM