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?
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);
The mimetypes for PHP are:
Where 'application/php' is the most common one I've seen.
You're Web.config XML code seems to work fine when using 'application/php' but you can also creata a mimetype mapping using the IIS manager (see: http://technet.microsoft.com/nl-nl/library/cc725608(v=ws.10).aspx).