automatically the right stylesheet

P

picayunish

Good day all,

I'm trying to make a php function so that the right stylesheet is loaded
for the browser.
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>
<link href="mac.css" rel="stylesheet" type="text/css">
<?php } else { ?>
<link href="windows.css" rel="stylesheet" type="text/css">
<?php } ?>
url is http://www.evandervaart/test2.php

Can I use this function for different browsers?
Or is there another function?
 
D

David Dorward

picayunish said:
I'm trying to make a php function so that the right stylesheet is loaded
for the browser.
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>

HTTP_USER_AGENT is unreliable at the best of times...

.... and what does the OS have to do with it? AFAIK the _only_ time the OS
has any influence over the rendering of CSS is the differences between
Windows IE and Mac IE.
Can I use this function for different browsers?

http://www.greytower.net/en/archive/articles/customcss.html might be of
interest.
 
K

kchayka

picayunish said:
Good day all,

I'm trying to make a php function so that the right stylesheet is loaded
for the browser.
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>
<link href="mac.css" rel="stylesheet" type="text/css">
<?php } else { ?>
<link href="windows.css" rel="stylesheet" type="text/css">
<?php } ?>
url is http://www.evandervaart/test2.php

url is http://www.evandervaart.nl/test2.php ;)

I imagine you'll be getting a bunch of replies on the advisability of
doing such a thing. The usual arguments...

What about other platforms, like linux, OS/2, etc.?

What is it about the platform that is browser agnostic? Mac Safari, Mac
IE, and Mac iCab are all very different. A platform-specific stylesheet
won't do any better than one stylesheet for all versions of Netscape.
Can I use this function for different browsers?

Why would you want to when there are much more reliable ways to present
different style rules to different browsers? Frankly, I'm surprised you
asked at all. I thought you knew better.
 
L

Leif K-Brooks

Toby said:
Although you may find that using good old-fashioned CSS hiding techniques,
such as:

html>body h1 {
color: red; /* IE for Windows won't see this. */
}

... is more reliable. It solves problems caused by browser spoofing and
caching proxies.

But it's more of a hack in another way, because a new version of IE may
add that CSS feature without adding the one you're hiding from it. At
least useragent sniffing will always hide it right.
 
D

David Dorward

Leif said:
But it's more of a hack in another way, because a new version of IE may
add that CSS feature without adding the one you're hiding from it. At
least useragent sniffing will always hide it right.

or would be if useragent spoofing wasn't so common.
 
N

Nico Schuyt

kchayka said:
picayunish wrote:
Frankly, I'm surprised you asked at all.
I thought you knew better.

So am I :) Must be the effect of a second bottle of Dutch Gin.
Semi, I told you before: no more than *one* bottle! (Like we say in Holland
"A bottle a day keeps the doctor away")
Nico
 
T

Toby A Inkster

Leif said:
But it's more of a hack in another way, because a new version of IE may
add that CSS feature without adding the one you're hiding from it.

Microsoft *may* inprove CSS parsing, but in that case they'll probably
accompany it with improvements to the rest of the CSS engine, possibly
allowing it to properly display what you've hidden from it.

In any case, if Microsoft release a new IE with significant changes in
CSS, you're going to probably have to rewrite parts of your style sheet
anyway.
At least useragent sniffing will always hide it right.

What about if a new version of IE changes the UA string to:

InternetExplorer/7.0 (Microsoft; Windows NT 5.2)

Will your user agent sniffing get it right then?

User agent sniffing will, as I said earlier, also get it wrong in the case
of browser spoofing. Which of these is really Internet Explorer???

"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98) Opera 7.21 [de]"
"Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)"

That's right! Neither! The first is Opera 7.21 and the second is Konqueror
3.1.0.
 
B

Bertilo Wennergren

Leif K-Brooks:
Toby A Inkster wrote:
But it's more of a hack in another way, because a new version of IE may
add that CSS feature without adding the one you're hiding from it.

A new version of IE might introduce a number of new bugs that break
things that work now. What can we do?
At least useragent sniffing will always hide it right.

No. Have you never heard of spoofing and proxies?
 
P

picayunish

David said:
picayunish said:
I'm trying to make a php function so that the right stylesheet is loaded
for the browser.
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>

HTTP_USER_AGENT is unreliable at the best of times...

... and what does the OS have to do with it? AFAIK the _only_ time the OS
has any influence over the rendering of CSS is the differences between
Windows IE and Mac IE.

OS hasn't anything to do with HTTP_USER_AGENT.
I only want to know how to use the HTTP_USER_AGENT for different browsers
with the right stylesheet.

Thanx for the link.
 
P

picayunish

kchayka said:
picayunish said:
Good day all,

I'm trying to make a php function so that the right stylesheet is loaded
for the browser.
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>
<link href="mac.css" rel="stylesheet" type="text/css">
<?php } else { ?>
<link href="windows.css" rel="stylesheet" type="text/css">
<?php } ?>
url is http://www.evandervaart/test2.php

url is http://www.evandervaart.nl/test2.php ;)

Oooops !!
I forgot the .nl
Thanx.
I imagine you'll be getting a bunch of replies on the advisability of
doing such a thing. The usual arguments...

What about other platforms, like linux, OS/2, etc.?

It was an example.
The intension for the script is for the different browsers and not for the
different platforms.
What is it about the platform that is browser agnostic? Mac Safari, Mac
IE, and Mac iCab are all very different. A platform-specific stylesheet
won't do any better than one stylesheet for all versions of Netscape.

Why would you want to when there are much more reliable ways to present
different style rules to different browsers? Frankly, I'm surprised you
asked at all. I thought you knew better.

To improve my php skills and sometimes I forget things.
If you point the direction or you could my give the url for the better way.
 
P

picayunish

Nico said:
So am I :) Must be the effect of a second bottle of Dutch Gin.
Semi, I told you before: no more than *one* bottle! (Like we say in
Holland "A bottle a day keeps the doctor away")

I didn't drink a Dutch Gin. ;-(
 
O

Owen Jacobson

picayunish said:
David said:
picayunish said:
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>

OS hasn't anything to do with HTTP_USER_AGENT.

Pardon? Then why are you checking for "win"?
I only want to know how to use the HTTP_USER_AGENT for different
browsers with the right stylesheet.

You can't rely on HTTP_USER_AGENT being accurate, or even present.
Some proxy servers will strip it off; some browsers fake being another
browser to get around stupid user-agent detection scripts that bounce
"unsupported" software... This has all been discussed before.
 
P

picayunish

Owen said:
picayunish said:
David said:
picayunish wrote:

What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>

OS hasn't anything to do with HTTP_USER_AGENT.

Pardon? Then why are you checking for "win"?

I was trying to use the following script at
http://www.evandervaart.nl/test.php
<?php
if(!eregi('Mozilla [0-9]+\.[0-9]+\(.+\)
Gecko.+',$_SERVER['HTTP_USER_AGENT'])) { ?>
<link href="http://members.chello.nl/e.vandervaart/gecko.css"
rel="stylesheet" type="text/css">
<?php
} elseif (!eregi('Opera
[0-9]+\.[0-9]+\(.+(MSIE)?.+\)',$_SERVER['HTTP_USER_AGENT'])) { ?>
<link href="http://www.semi-conductor.nl/test/opera.css" rel="stylesheet"
type="text/css">
<?php
} elseif (!eregi('MSIE
[0-9]+\.[0-9]+\(.+MSIE.+\).*',$_SERVER['HTTP_USER_AGENT'])){ ?>
<link href="http://www.semi-conductor.nl/msie.css" rel="stylesheet"
type="text/css">
<?php
} else { print ("Dit gaat fout "); } ?>

http://www.evandervaart.nl/test2.php is the original php script, that is
checking for OS.
You can't rely on HTTP_USER_AGENT being accurate, or even present.
Some proxy servers will strip it off; some browsers fake being another
browser to get around stupid user-agent detection scripts that bounce
"unsupported" software... This has all been discussed before.

Hmmm.
I didn't read follow that thread, I'll look it up in the archive.
 
K

kchayka

picayunish said:
To improve my php skills and sometimes I forget things.

OK, you didn't make your real intentions clear. If you are merely
trying to improve your php skills, that's one thing, but actually
relying on the UA string for anything important is awfully unreliable.
If you point the direction or you could my give the url for the better way.

<URL:http://w3development.de/css/hide_css_from_browsers/>
<URL:http://centricle.com/ref/css/filters/>
<URL:http://accessat.c-net.us/articles/hide-css_p1.html>
 
D

David Dorward

picayunish said:
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>

HTTP_USER_AGENT is unreliable at the best of times...
OS hasn't anything to do with HTTP_USER_AGENT.

You have a function to guess which OS the user is using, and that function
uses HTTP_USER_AGENT, but HTTP_USER_AGENT has nothing to do with the OS? So
why use it? You might want to try understanding what your existing code
does before adding to it.
 
P

picayunish

David said:
picayunish said:
What if have is a function for 2 different OS:
<?php if(!eregi('win',$_SERVER['HTTP_USER_AGENT'])){ ?>

HTTP_USER_AGENT is unreliable at the best of times...
OS hasn't anything to do with HTTP_USER_AGENT.

You have a function to guess which OS the user is using, and that
function uses HTTP_USER_AGENT, but HTTP_USER_AGENT has nothing to do
with the OS? So why use it? You might want to try understanding what
your existing code does before adding to it.

If I changed the $_SERVER into $_BROWSER has it still have to do with the
OS?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top