WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-30-2007, 02:36 AM
WebProWorld Member
 

Join Date: Nov 2006
Location: Seattle
Posts: 54
shannonlp RepRank 0
Default 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....
__________________
Web Designer and Custom Spider Creator
eCommerce and shopping cart information
Reply With Quote
  #2 (permalink)  
Old 08-01-2007, 12:42 AM
WebProWorld Pro
 

Join Date: May 2007
Location: DataCenter
Posts: 174
hostBrain RepRank 1
Default Re: A little PHP function that might be helpful

Neat script, thanks for sharing... got rep

Question: Shouldn't each code call a different css file? or am i not getting it?

ps, your site took forever to load
__________________
----Don't Call Me Brian----
Reply With Quote
  #3 (permalink)  
Old 08-01-2007, 03:54 PM
WebProWorld Member
 

Join Date: Nov 2006
Location: Seattle
Posts: 54
shannonlp RepRank 0
Default Re: A little PHP function that might be helpful

Thanks,

Yes each css file can be different if needed. You could render a completely different site base on each browser type.

I am upgrading the site and about to move it to a new server. When finished it will have every shopping cart system I have found showing features and overall functionality.
__________________
Web Designer and Custom Spider Creator
eCommerce and shopping cart information
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: , , , ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Helpful Strategy? SEOforGoogle Marketing Strategies Discussion Forum 6 11-14-2007 10:23 AM
PHP help - function call bilabong Web Programming Discussion Forum 0 07-22-2007 06:56 AM
PHP isset () function kurt.santo Web Programming Discussion Forum 2 07-02-2007 03:47 AM
PHP Function Calls via Links? southplatte Web Programming Discussion Forum 4 07-27-2004 10:47 PM
Feedback would be helpful kimmichelle Introductions 0 05-07-2004 07:01 PM


Search Engine Optimization by vBSEO 3.2.0