TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-02-2009, 10:08 AM   #1 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default what method do you use with php when displaying a stylesheet?

this is how i display a style sheet for whatever browser that opens the page.

Code:
function style() {
$browser = $_SERVER['HTTP_USER_AGENT'];
if(preg_match('/MSIE6.0/',$browser)) {
echo "ie6.css";
}

if(preg_match('/Firefox/',$browser)) {
echo "firefox.css";
}
}

//then in the html i put something like this

<head>
<link href="css/<?php style(); ?>" type="text/css" rel="stylesheet">
</head>
is there a better method to do than doing it this way? since this is the only way that i know i'm wasting more time by creating a stylesheet for every browser that exists than finding another way.

whats another way of doing this??


thanks
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-02-2009, 12:41 PM   #2 (permalink)
The Visitor
 
Join Date: Aug 2008
Posts: 4
Thanks: 0
enzochi@gmail.com is on a distinguished road
Default

you could just use HTML conditional statements:

<!--[if IE]>
<link href="/includes/ie-fixes.css" rel="stylesheet" type="text/css" />
<![endif]-->

there is also get_browser() for php:

$browser = get_browser(null, true);
print_r($browser);

personally I use the html method.. i've used the php method and i like it but it won't work on all servers if it's not setup properly.
enzochi@gmail.com is offline  
Reply With Quote
Old 01-02-2009, 02:20 PM   #3 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

I usually use a main style sheet which holds all styles that good browsers render properly and for the retarded browsers i use conditional statements to overwrite specific styles:

HTML Code:
<link rel="stylesheet" href="main.css" type="text/css" />
<!--[if lte IE 6]>
     <link rel="stylesheet" type="text/css" href="ie-6.css" />
<![endif]-->
<!--[if IE 7]>
     <link rel="stylesheet" type="text/css" href="ie-7.css" />
<![endif]-->
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
sarmenhb (01-03-2009)
Old 01-02-2009, 09:25 PM   #4 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

thanks, but what do you put for other browsers?

like firefox, chrome, etc do you have to write a javascript for each browser?

cause i noticed chrome acts a little different since its a mozilla engine.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-02-2009, 09:46 PM   #5 (permalink)
The Visitor
 
Join Date: Aug 2008
Posts: 4
Thanks: 0
enzochi@gmail.com is on a distinguished road
Default

the conditionals only work for IE (I can't find anywhere that would suggest different). The way I work this out is to develop for FF/Safari/Opera. Then make it work in IE. Those three seem to work better with standard code. IE really needs the shims to get everything to look correct. And these three cover the basic html render engines. These same rules apply for JavaScript too..

here is a link for the conditionals..
http://www.dedestruct.com/2008/04/03...onal-comments/
enzochi@gmail.com is offline  
Reply With Quote
Old 01-02-2009, 10:05 PM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Chrome is built on webkit, which is the very same engine as safari. General rule of thumb (i find anyway) if it works in chrome, it will generally work in safari.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
sarmenhb (01-03-2009)
Old 01-03-2009, 03:22 AM   #7 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

how about i start working on a project to make a major reset either stylesheet or php file that will be included into a page and make all major browsers all work the same as a primary browser in this case be firefox. if anyone is interested in helping out let me know.

we gotta end this problem.
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Old 01-08-2009, 10:16 AM   #8 (permalink)
The Contributor
 
Join Date: Apr 2005
Location: Kent, UK
Posts: 54
Thanks: 0
Dr John is on a distinguished road
Default

All you need to do is design for Firefox, correct for IE using conditional statements, and that's it.

There is no need what so ever to have a separate css file for each browser, because if it works in FF, it should work in all modern browsers. Browser sniffing is not used now. Especially as some browsers can pretend to be other browsers and thus feed your script duff data.
__________________
www.kidneydialysis.org.uk
Dr John is offline  
Reply With Quote
Old 01-08-2009, 12:01 PM   #9 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

The easiest way is to use a framework really. The frameworks handles the mass reset etc.

Read this thread New CSS framework: BlueTrip for a good framework.
maZtah is offline  
Reply With Quote
Old 01-08-2009, 02:36 PM   #10 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

If you actually know css you can almost always get it down to 1 style sheet and not have to worry about this at all. However every now and then ie will act up and you can just use the html conditions as stated above to fix this.

The best way to avoid this is to have all 4 browsers up at once (FF/Opera/Chrome/IE7) and after every css change refresh the page one all 4 until you get it right in all 4. Then this whole mess can be avoided. It might take a little bit longer but its much easier once it works.
CoryMathews is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Tips: Fastest PHP Code jordie Tips & Tricks 8 05-14-2013 12:47 PM
10 PHP Myths Dispelled Wildhoney General 9 06-15-2009 06:55 AM
PHP Compressor Kalle Script Giveaway 8 05-28-2008 12:14 AM
Tips: PHP security Village Idiot Tips & Tricks 22 11-23-2007 11:17 PM
My Favourite PHP Magic Method: __call Wildhoney Advanced PHP Programming 10 11-16-2007 03:32 AM


All times are GMT. The time now is 12:44 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design