automatically the right stylesheet

Discussion in 'HTML' started by picayunish, Nov 24, 2003.

  1. picayunish

    picayunish Guest

    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?
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://www.evandervaart.nl/ Underconstruction
     
    picayunish, Nov 24, 2003
    #1
    1. Advertising

  2. picayunish wrote:

    > 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.

    --
    David Dorward http://dorward.me.uk/
     
    David Dorward, Nov 24, 2003
    #2
    1. Advertising

  3. picayunish

    kchayka Guest

    picayunish wrote:

    > 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.

    --
    To email a reply, remove (dash)un(dash). Mail sent to the un
    address is considered spam and automatically deleted.
     
    kchayka, Nov 24, 2003
    #3
  4. Toby A Inkster, Nov 24, 2003
    #4
  5. Toby A Inkster wrote:
    > 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.
     
    Leif K-Brooks, Nov 25, 2003
    #5
  6. Leif K-Brooks 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. At
    > least useragent sniffing will always hide it right.


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

    --
    David Dorward http://dorward.me.uk/
     
    David Dorward, Nov 25, 2003
    #6
  7. picayunish

    Nico Schuyt Guest

    kchayka wrote:
    > picayunish wrote:


    >> I'm trying to make a php function so that the right stylesheet is
    >> loaded for the browser.


    > 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
     
    Nico Schuyt, Nov 25, 2003
    #7
  8. Leif K-Brooks wrote:

    > Toby A Inkster wrote:
    >> 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.


    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.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me - http://www.goddamn.co.uk/tobyink/?page=132
     
    Toby A Inkster, Nov 25, 2003
    #8
  9. Leif K-Brooks:

    > Toby A Inkster wrote:


    >> 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.


    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?

    --
    Bertilo Wennergren <> <http://www.bertilow.com>
     
    Bertilo Wennergren, Nov 25, 2003
    #9
  10. picayunish

    picayunish Guest

    David Dorward wrote:
    > picayunish wrote:
    >
    >> 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.

    >> Can I use this function for different browsers?

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


    Thanx for the link.
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://www.evandervaart.nl/ Underconstruction
     
    picayunish, Nov 25, 2003
    #10
  11. picayunish

    picayunish Guest

    kchayka wrote:
    > picayunish wrote:
    >
    >> 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.


    >> 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.


    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.
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://www.evandervaart.nl/ Underconstruction
     
    picayunish, Nov 25, 2003
    #11
  12. picayunish

    picayunish Guest

    Nico Schuyt wrote:
    > kchayka wrote:
    >> picayunish wrote:

    >
    >>> I'm trying to make a php function so that the right stylesheet is
    >>> loaded for the browser.

    >
    >> 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")


    I didn't drink a Dutch Gin. ;-(
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://www.evandervaart.nl/ Underconstruction
     
    picayunish, Nov 25, 2003
    #12
  13. picayunish wrote:

    > David Dorward wrote:
    > > 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 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.
     
    Owen Jacobson, Nov 25, 2003
    #13
  14. picayunish

    picayunish Guest

    Owen Jacobson wrote:
    > picayunish wrote:
    >
    >> David Dorward wrote:
    >>> 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.

    >> 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.


    Hmmm.
    I didn't read follow that thread, I'll look it up in the archive.
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://www.evandervaart.nl/ Underconstruction
     
    picayunish, Nov 25, 2003
    #14
  15. picayunish

    kchayka Guest

    picayunish wrote:
    > kchayka wrote:
    >> picayunish wrote:
    >>
    >>> I'm trying to make a php function so that the right stylesheet is loaded
    >>> for the browser.

    >>
    >> Why would you want to when there are much more reliable ways to present
    >> different style rules to different browsers?

    >
    > 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>

    --
    To email a reply, remove (dash)un(dash). Mail sent to the un
    address is considered spam and automatically deleted.
     
    kchayka, Nov 26, 2003
    #15
  16. picayunish

    Nico Schuyt Guest

    picayunish wrote:
    > Nico Schuyt wrote:
    >> kchayka wrote:
    >>> picayunish wrote:

    >>
    >>>> I'm trying to make a php function so that the right stylesheet is
    >>>> loaded for the browser.

    >>
    >>> 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")


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


    Too bad, I hoped I had found an excuse for you :)
    Nico
     
    Nico Schuyt, Nov 26, 2003
    #16
  17. picayunish

    picayunish Guest

    picayunish, Nov 26, 2003
    #17
  18. picayunish wrote:

    >>> 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.


    --
    David Dorward http://dorward.me.uk/
     
    David Dorward, Nov 26, 2003
    #18
  19. picayunish

    Nico Schuyt Guest

    picayunish wrote:
    > kchayka wrote:
    >> picayunish wrote:


    >>> 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


    > Thanx Kchayka.


    Very polite. But I'm absolutely sure you already knew the techniques of
    hiding CSS.
    Still think it's the Dutch Gin that confused you :)
    Nico
     
    Nico Schuyt, Nov 27, 2003
    #19
  20. picayunish

    picayunish Guest

    David Dorward wrote:
    > picayunish wrote:
    >
    >>>> 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?
    --
    Edwin van der Vaart
    http://www.semi-conductor.nl/ Links to Semiconductors sites
    http://www.evandervaart.nl/ Underconstruction
     
    picayunish, Nov 27, 2003
    #20
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    578
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  2. Steven An
    Replies:
    1
    Views:
    504
    Martin Honnen
    Nov 23, 2004
  3. David Blickstein
    Replies:
    3
    Views:
    1,039
    David Blickstein
    Aug 2, 2005
  4. David Blickstein
    Replies:
    14
    Views:
    6,341
    Harrie
    Oct 16, 2005
  5. Ehsan Khoddam mohammadi

    unsigned right shift casts to int automatically!!!

    Ehsan Khoddam mohammadi, Jan 4, 2007, in forum: Java
    Replies:
    2
    Views:
    415
    Ehsan Khoddam mohammadi
    Jan 4, 2007
Loading...

Share This Page