doudian7996 2014-01-28 14:30
浏览 21
已采纳

你如何使IIS 7解析js文件也作为PHP文件?

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

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.

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>

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?

  • 写回答

2条回答 默认 最新

  • douxun4173 2014-01-28 16:13
    关注

    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("
    ")===-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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题