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 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)