Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Identifying browsers

by Melly (Chaplain)
on Mar 30, 2001 at 16:38 UTC ( [id://68350]=perlquestion: print w/replies, xml ) Need Help??

Melly has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I need to identify access to my cgi/perl script by NS4 users, so that I can disable CSS. The problem is that the string returned by NS4 in HTTP_USER_AGENT is very variable for the different versions of NS4.

Does anyone know of any resource, script or module that can help with this?

BTW, sorry if I've posted this twice (once as anonymous) - first time using this site (sigh).

Replies are listed 'Best First'.
Re: Identifying browsers
by davorg (Chancellor) on Mar 30, 2001 at 17:42 UTC

    The CPAN is your friend. Use the CPAN, Luke!

    I've never used it, but HTTP::BrowserDetect looks like it might be just want you want.

    --
    <http://www.dave.org.uk>

    "Perl makes the fun jobs fun
    and the boring jobs bearable" - me

      Ahh! I will check it out - many thanks
      Tom Melly, tom@tomandlu.co.uk
Re: Identifying browsers
by merlyn (Sage) on Mar 30, 2001 at 17:47 UTC
    Please be sure that when you do this, you also mark your page as dynamic (non-cacheable), or you redirect to a different URL for the distinguished browsers. Otherwise, proxy-caches will save your NS4 page for delivery to a non-NS4 browser, or vice versa.

    -- Randal L. Schwartz, Perl hacker

      I've set an expires of -1, would this be enough?
      Many thanks, btw, I hadn't thought of this problem. Tom Melly, tom@tomandlu.co.uk
Re: Identifying browsers
by Malkavian (Friar) on Mar 30, 2001 at 17:40 UTC
    Hmm.. I may be in error here, but, I believe the browser string for NS 4 returns a very similar string for a portion of it (i.e. Mozilla/4.xxx).
    I think the solution in this case would be to filter for this particular string using a regular expression.
    Also, a lot of browsers return Mozilla 4.0 compatible in the string. You'll need to make sure that you don't classify the 4.0 compatibles as NS4.x, as this includes most of the up to date browsers that do support CSS.
    Just a thought, good luck with it. :)

    Cheers,

    Malk
      Sounds reasonable - I wasn't sure whether other browsers returned Mozilla 4.xx where xx was any other value except 0.
      Tom Melly, tom@tomandlu.co.uk
Re: Identifying browsers
by Masem (Monsignor) on Mar 30, 2001 at 17:45 UTC
    Unfortunately, the HTTP_USER_AGENT is not a good way to identify browsers, despite 99% of dot.com business sites that think they can. This is easily faked and could also change if the user is behind a proxy. If you really need to , you can try to match with m#Mozilla/4\.\d#, but do it with full understanding of mislabelled browser.

    A better question to ask yourself is why you need to disable CSS for NS4 browser. Yes, I do know that NS4 (paricularly before 4.5) does have some CSS oddities, but a lot of them are a result of poor web page writting or or CSS set up. While it's outside the scope of PM, it might be helpful to know what CSS NS is choking on.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

      I disagree - Netscape 4 is horribly broken when it comes to CSS :

      • Netscape loses CSS information when you resize the window.
      • Netscape has coupled JavaScript and CSS, you can't have CSS without allowing JavaScript.
      • css.nu has a looong list of what other problems there are with CSS and Netscape 4.

      Of course, the solution is to either generate special pages for Netscape 4 or to go back to complete .jpg images together with imagemaps for the navigation or creating the pages alltogether in MacroMedia Flash, if you need pixel-exact layout. Other than that, I see no way to give people using broken tools fancy layout.

        When you get down to it, no browser has good CSS 1 support, much less CSS 2. NS 4 as pointed out has a ton more bugs in CSS rendering as compared to IE5 or Opera. Save for the coupled JS/CSS thing, most of these bugs manifest themselves when you start using positioning features; in otherwords, I've typically found that using CSS to denote font changes, indenting, and other such features is not going to cause NS to blow up at you.

        But my comment was more towards why one needs to browser detect anyway. Even if you browser detect correctly, and send off a CSS file for that browser, *my* user CSS that might specify Monospace 40pt where you have Sans Serif 10pt is going to most likely cause your entire page to render incorrectly particularly if you are using CSS to position elements rather than thinking of the items within the stream of text. As Corion states above, if you are looking for pixel-perfect placement , it's best to drop back to graphic files or flash or PDF to do this.

        As Milly points out in another reply, a link near the top of the page for a non-CSS version (which simply doesn't need to send off a CSS file, as opposed to removing all CSS tags) is a very good solution that works in conjunction with having CSS pages without resorting to browser detection. If I come to a site with NS4 that had something like this, warning that "If the layout of this page is screwed up, try this version of this page", I would think this is just as good if not better than trying to guess the browser and play the same games here. And it would be much less work on the server too.


        Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      BTW I intend to add an option for users to turn off CSS, irrespective of browser ID, so even if I misidentify, the site will still be usable.
      Many thanks for the advice
      Tom Melly, tom@tomandlu.co.uk

      Basically, a link with CSS applied to it stops acting as a link.

      The url of my script is http://cgi.tomandlu.plus.com/cgi-bin/links.cgi and the CSS is the same domain but /avx/links.css

      Tom Melly, tom@tomandlu.co.uk
Re: Identifying browsers
by Chady (Priest) on Mar 31, 2001 at 01:11 UTC
    lots of CSS and browser compatibility is being talk about at The WaSP Project.
    Also you can see what Jeffery Zeldman has to say about it.
    A List Apart is one of my favorite too.
    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://68350]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found