Closed Thread Icon

Preserved Topic: CSS and Browser Detection... Pages that link to <a href="https://ozoneasylum.com/backlink?for=18300" title="Pages that link to Preserved Topic: CSS and Browser Detection..." rel="nofollow" >Preserved Topic: CSS and Browser Detection...\

 
Author Thread
WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 08-18-2001 21:09

With the advent of CSS2 and non-table design I was prompted to design two different templates. One template to be completely CSS2 complient. Using CSS for possitioning and the like. And another version that uses tables for the possitioning.

Now here comes the interesting part. Using PHP I would like to swap header and footer files depending upon the browser being used by the user.

This presents a problem for me. I am not sure which browsers are standard compliant. Anyone know?

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-18-2001 21:13

IE5.5 & IE6, Mozilla/NS6, Opera5

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 08-18-2001 21:56

Thanks max!

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 08-18-2001 22:01
code:
<? 
$agent = getenv("HTTP_USER_AGENT");

if (preg_match("/MSIE5.5/i", "$agent") &#0124; &#0124; preg_match("/MSIE6/i", "$agent") &#0124; &#0124; preg_match("/Mozilla/i", "$agent") &#0124; &#0124; preg_match("/NS6/i", "$agent"))
{
//Give CSS Template
}
else
{
//Give Tables Template
}
?>



So I could use this code to get the desired effect?

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-18-2001 22:10

Nope, you should use this instead:

$standards = preg_match("/(MSIE5\\.5

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 08-18-2001 22:14

Thats pretty slick!

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 08-19-2001 13:07

If you are planning a standards compliant website then the Web Stanards web site will give you all the information on what browsers count as compliant:
http://www.webstandards.org

Basically what Mr.Max said should work unless you are attempting to do something more complex. This browser/platform detector:
http://www.phpbuilder.com/snippet/detail.php?type=snippet&id=8

, while pretty lengthy, could be adapted for your needs so you can target the correct versions platforms.

Emps

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-19-2001 13:42

That code from PHPBuilder is very inefficient... Much simpler code that I wrote which does more or less the same job can be found here: http://www.ozoneasylum.com/Forum8/HTML/000183.html

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 08-19-2001 18:33

http://www.webstandards.org/upgrade/

That is the page that supplies what browsers are supporting standards.

I would be appreciative if anyone had a link to a resourse of what is returned via getenv(HTTP_USER_AGENT)

There are many different browsers out there, and I would have no idea how to know what each HTTP_USER_AGENT would be for the different browsers.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-19-2001 21:02

The line of code that I wrote will correctly match all browsers listed on that page, with exception of MSIE5 for Mac, but it can be added very easy (simply search for words "MSIE5" and "Mac")

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 08-20-2001 17:10

http://sourceforge.net/projects/phpsniff/

This is the most robust browser sniffer. It has functions to pull any bit of information you want about almost any browser. Might not be as efficient as Max's, but it will guarantee that you don't have to rewrite it later when you discover browser discrepencies.

BTW, IE5.5 still does not support the correct box model (which is important for CSS based layouts). There are also many other minor differences that can come into play, most notably for my site was the way lists handle their indentation/left margin in different browsers.

I actually load a main stylesheet, then have a number of if statements that load other stylesheets on top based on what particular browsers need modified.

-jiblet

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 08-20-2001 18:56

Just a small suggestion - if you don't have a very complex web site, using complex libraries like phpSniff would be overkill for web server...

jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 08-20-2001 19:25

True dat. I guess not everyone is building sites on a dedicated server that serves <1000 pages a day

-jiblet

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 02-08-2002 08:54

I'm bumping this up from way back when because I'm trying to see if I can detect the user's screen resolution info from a HTTP_USER_AGENT or some similar env. Can it be done?

I would love something as cool as:
$standards = preg_match("/(MSIE5\\.5

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 02-08-2002 18:52

I'm pretty sure this can't be done.

Hopefully someone will tell you for sure but I don't think that info is sent in the general header info sent and recieved in the headers.

You could do somesort of trickiness on the client side though, like make a landing page that does the detect and then redirects the user to a page with the info encoded in the URL.





:[ Computers let you make more mistakes faster than any other invention in human history, with the possible exceptions of handguns and tequila. ]:

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 02-08-2002 19:48

Screen resolution can only be determined on the client-side. It's not sent with HTTP headers...


Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 02-08-2002 20:28

Ok, thanks. I figured if anyone knew, you all would I'll just have to modify my plans just a bit but I think my page will still work out ok.

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 02-08-2002 22:28

Max -

So, testing your line
<B>$standards = preg_match("/(MSIE5\\.5

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 02-08-2002 22:35

Or better yet

<?php
$standard = preg_match("/(MSIE5\\.5

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 02-08-2002 22:48

if (preg_match("/(MSIE5\\.5

« BackwardsOnwards »

Show Forum Drop Down Menu