简体   繁体   English

如何使用PHP获取用户的Java版本?

[英]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? 是否有一种简单的解决方案来获取使用php在用户工作站上运行的Java版本? Basically I want to know the version of Java running on a user's machine who accesses my portal. 基本上,我想知道在访问我的门户的用户计算机上运行的Java版本。 This data will help me make some policy decisions later since our product is Java based. 由于我们的产品基于Java,因此这些数据将有助于我稍后做出一些政策决策。

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. 可以同时(间接)访问客户端(以确定信息)和服务器端(发送信息)的唯一客户端语言是JavaScript和ActionScript。

I think you're as being a PHP programmer already less or more familiar with JavaScript, so I would go ahead with that. 我认为您已经成为PHP程序员,已经或多或少地熟悉JavaScript,所以我会继续做下去。 Fortunately Sun already offers the Java Deployment Toolkit JavaScript library exactly for those needs. 幸运的是,Sun已经为这些需求提供了Java Deployment Toolkit JavaScript库。 Here's an SSCCE , just copy'n'paste'n'run it: 这是一个SSCCE ,只需复制“ 粘贴 ”即可运行它:

<!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. 您可以通过将其作为表单的隐藏输入元素传递来同步进行,也可以使用Ajaxical技术异步进行。 jQuery is perfectly suitable for this. jQuery非常适合于此。 Just do a $.get('script.php?java=' + deployJava.getJREs()); 只需执行$.get('script.php?java=' + deployJava.getJREs()); or so. 或者。

Check javatester.org they use a little applet to get the running JVM version. 检查javatester.org,他们使用一个小程序来获取运行中的JVM版本。 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 . 如果Java正在运行,只需调用服务器上放置的脚本,User-Agent应该为您提供运行时环境的确切版本 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. 由于部署工具包的javascript代码最多只能列出Java 6的多达17个发行版本……以及更早的版本,因此您必须猜测特定浏览器使用的是哪个版本。

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. 如果他们正在通过Web浏览器访问您的网站,那不是在用户代理字符串中显示的那种东西。

On the other hand, if they are programmatically accessing your site with Java code, then it will show up in the user agent string. 另一方面,如果他们使用Java代码以编程方式访问您的网站,则该网站将显示在用户代理字符串中。 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. browser_get()函数将尝试告诉您是否可以执行Java applet。

With PHP alone I believe this is your best bet. 仅凭PHP,我相信这是您最好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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