如何使IIS 7解析js文件也可作为一个PHP文件? [英] How do you make IIS 7 parse a js file also as a PHP file?

查看:120
本文介绍了如何使IIS 7解析js文件也可作为一个PHP文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后,我试图让设置我的服务器上特别可靠的方法来检测别人的浏览器的名称和版本(日志,不启用功能),有人指出的这个项目的了。话虽这么说,他们正在使用具有下列内容的htaccess文件:

Ultimately I'm trying to get a particularly reliable way set up on my server to detect somebody's browser name and version (for logging, not enabling features), and somebody pointed this project out. That being said, they're using an htaccess file with the following contents:

AddType application/x-httpd-php .js

他们的自述文件说,这是为了让服务器也使用PHP解析某个js文件,并且,如果没有启用htaccess的,你必须要找到一个变通办法。

Their readme file said that this was to get the server to also use PHP to parse a certain js file, and that if htaccess is not enabled, you have to find a work-around.

我使用的是IIS 7,它使用的web.config文件,但我看不出来的最现成的MIME类型PHP在互联网上,所以做这样的事情看起来并不像它的上班:

I'm using IIS 7, which uses web.config files, but I don't see an out-of-the-box mime type for PHP on the Internet, so doing something like this doesn't look like it's going to work:

<configuration>
   <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".js" mimeType="PHP mime type" />
      </staticContent>
   </system.webServer>
</configuration>

我试图用的这个建议,其中涉及通过IIS GUI添加处理程序映射,但是这似乎并没有任何平移它。如何才能做到这一点?

I tried using this suggestion, which involved adding handler mappings through the IIS GUI, but that didn't seem to pan it either. How can this be done?

推荐答案

我通过增加一个处理程序映射到IIS得到了这个工作。我所做的只是与请求路径使用设置为 detect.js 添加处理程序映射的 FastCgiModule ,显然指挥可执行文件路径,其中名为php-cgi.exe 是我的服务器上。然后,PHP被解析detect.js很好,我碰到了,而试图让这个工作唯一的麻烦是,创建了 WhichBrowser 对象是正在运行的code在 detect.js 脚本加入前/加载到给定的测试网页。为了解决这个问题,我只是修改了code给出这里,这样的:

I got this working by adding a handler mapping to IIS. All I did was add the handler mapping with Request path set to detect.js using the FastCgiModule and obviously directing the executable path to where php-cgi.exe is on my server. Then php was parsing detect.js fine, the only trouble I ran into whilst trying to get this to work was that the code that created the WhichBrowser object was being run before the detect.js script was added/loaded to the given test webpage. To fix this I simply modified the code given here, to this:

<script>
(function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
    e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
    e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
    f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
    p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
    s.src='http://intranet.zachs/media/whichbrowser/detect.js?' + p.join('&');

    s.onreadystatechange= function () {
          if (this.readyState == 'complete') go();
       }
       s.onload= go;
    s.type="text/javascript";
    d.getElementsByTagName('head')[0].appendChild(s);
    })();

然后在我的函数我只是有:

Then in my go function i just have:

Browsers = new WhichBrowser();
alert("Browser Info: " + Browsers);

这篇关于如何使IIS 7解析js文件也可作为一个PHP文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆