A little PHP function that might be helpful
I ran across a PHP script that would read your browser and then assign the proper CSS link for the browser.
The orginal version can be found at :
+------------------------------------------------------------------+
| MikeCherim.com |
| PHP: Browser Sniffer |
| PHP Hypertext Preprocessor |
| Copyright July 2006 |
| Use with attribution by visible link please! |
| Attribute to: <a href="http://green-beast.com/">Mike Cherim</a> |
+------------------------------------------------------------------+
Thought I would share my version. Found it to be helpful for a project that I am working on right now.
This is the core file I named it "browsers.inc.php"
<?php
function load_css() {
$ua_ok= $_SERVER['HTTP_USER_AGENT'];
// First the Windows( PC) browsers ****************************
// Win Internet Explorer 7.0
if( eregi( "Windows", $ua_ok ) &&
eregi( "msie", $ua_ok ) &&
eregi( "[7]\.[0]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" media="screen" />' );
}
// Win Internet Explorer 6.x or AOL 9.x
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "msie", $ua_ok ) &&
eregi( "[6]\.[0-9]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" media="screen" />' );
}
// Win Internet Explorer 5.5
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "msie", $ua_ok ) &&
eregi( "[5]\.[5]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" media="screen" />' );
}
// Win Firefox 3.0
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "firefox", $ua_ok ) &&
eregi( "[1]\.[9]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Win Firefox 2.0
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "firefox", $ua_ok ) &&
eregi( "[1]\.[8]\.[1]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Win Firefox 1.5.0
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "firefox", $ua_ok ) &&
eregi( "[1]\.[5]\.[0]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Win Firefox 1.0.7
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "firefox", $ua_ok ) &&
eregi( "[1]\.[0]\.[7]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Win Mozilla 1.7.12
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "mozilla", $ua_ok ) &&
!eregi( "netscape", $ua_ok ) &&
eregi( "rv:[1]\.[7]\.[12]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Win Mozilla 1.6
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "mozilla", $ua_ok ) &&
eregi( "rv:[1]\.[6]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Win Netscape 6.2
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "netscape", $ua_ok ) &&
eregi( "[6]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Win Safari 3
elseif( eregi( "Windows", $ua_ok ) &&
eregi( "safari", $ua_ok ) &&
eregi( "[3]\.[0]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Now the Mac browsers ****************************************
// Mac Firefox 2.0
elseif( eregi( "Macintosh", $ua_ok ) &&
eregi( "firefox", $ua_ok ) &&
eregi( "[1]\.[8]\.[1]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Mac Firefox 3.0
elseif( eregi( "Macintosh", $ua_ok ) &&
eregi( "firefox", $ua_ok ) &&
eregi( "[1]\.[9]", $ua_ok ) ) {
echo( '<link href="www.ecarttemplates.com/css/elayoutFF2_0_MAC.css" rel="stylesheet" type="text/css" />' );
}
// Mac Opera 9.x
elseif( eregi( "Macintosh", $ua_ok ) &&
eregi( "opera", $ua_ok ) &&
eregi( "[9]", $ua_ok ) ) {
echo( '<link href="www.ehttp://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Mac Safari 2.0
elseif( eregi( "Macintosh", $ua_ok ) &&
eregi( "safari", $ua_ok ) &&
eregi( "[417]\.[0-9]\.[0-9]", $ua_ok ) ) {
echo( '<link href="http://www.http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
// Mac Safari 2.0.4
elseif( eregi( "Macintosh", $ua_ok ) &&
eregi( "safari", $ua_ok ) &&
eregi( "[419]\.[0-9]", $ua_ok ) ) {
echo( '<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />' );
}
}
?>
-----------------------------------------------------------------------------------------------
Then in your index.php
top of page
<?php require "browsers.inc.php" ?>
Then within the head tag below
<link href="http://www.yourdomain.com/css/layout.css" rel="stylesheet" type="text/css" />
insert
<?php load_css() ?>
It really helped me hope it can help someone....
|