Browser info and redirect
penra
Status: Curious
Joined: 03 Sep 2004
Posts: 7
Reply Quote
Your scripts are works of art to me!
I've been using a stupid javascript that is too dumb to detect the difference between Safari and IE 5.x and so my users with Safari are getting the bad news page, "you can't see our site".

:: Code ::
<!--
function MM_checkBrowser(NSvers,NSpass,NSnoPass,IEvers,IEpass,IEnoPass,OBpass,URL,altURL) { //v4.0
  var newURL='', verStr=navigator.appVersion, app=navigator.appName, version = parseFloat(verStr);
  if (app.indexOf('Netscape') != -1) {
    if (version >= NSvers) {if (NSpass>0) newURL=(NSpass==1)?URL:altURL;}
    else {if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;}
  } else if (app.indexOf('Microsoft') != -1) {
    if (version >= IEvers || verStr.indexOf(IEvers) != -1)
     {if (IEpass>0) newURL=(IEpass==1)?URL:altURL;}
    else {if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;}
  } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
  if (newURL) { window.location=unescape(newURL); document.MM_returnValue=false; }
}
//-->

Thats what I've been using and I would rather use a php script to do that and more.
At this point, I'm not sure where to begin. I've validated my site with every os/browser combo and the three that break are the only ones I want to redirect. Those three are Macintosh/IE and Macintosh/NS4.x and Windows/NS4.x.
I think I can craft my css to work with the window/NS4 but later not today.
Can you help me out here?
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Easiest way is to set headers on with php. When you set a header no other code at all can appear before this code, including a blank space on the html page.

:: Code ::
<?php
include('browser_detection.php');

$a_browser_data = browser_detection('full');
$browser = $a_browser_data[0];
$number = $a_browser_data[1];
$os = $a_browser_data[5];
$ie_version = $a_browser_data[2];

if ( ( $ie_version == 'ieMac' ) || ( $browser == 'ns' ) )
{
header("Location: http://www.yoursite.com/your-redirect-page.html");
}
?>
<html>
<title... and so on

You can make it more complicated than that but you don't need to, 'ns' identifies only Netscape 4x and lower netscapes, so that catches the mac and windows ones. Don't waste your time trying to get the windows ns 4x css to work unless it's a commercial job where that 1% or so actually matters, that browser is going fast, soon will be gone.

Questions on includes are answered in the apache forum and this forum, please read through them before asking how to do basic things.

Glad you liked the script, wish I could call it art but the Operating system component is just not that good, it works ok but that's it. But I will agree that most other browser detection scripts out there really suck, that's why I wrote this one. The javascript one is pretty good too by the way, but the thing with old browsers is the users almost always have javascript support turned off since if you try having it on all you will see is endless error boxes when you go to any modern website, so detecting old browsers with javascript is pretty much a waste of time, and doesn't help your users.


==========================================

Much easier, by the way, is just using css @import rules to filter out browser x or y.

For your purposes, this CSS import rule can be very useful, since you can simply give these browsers no css using this method, just give them the raw html, which is usually better looking than weakly styled or broken css:

@import '/css/yourstyles.css'; [read more here]

This precise syntax blocks all NS 4x and earlier, and all Mac IE browsers, but also IE 4 windows, but all other modern browsers support that syntax.
Back to top
penra
Status: Curious
Joined: 03 Sep 2004
Posts: 7
Reply Quote
thank you that seems to work great. I'll have a friend with Mac check it out further.

I'll try the @import, this is an IPBNuke site.
thanks again for sharing your scriptwork.
Back to top
penra
Status: Curious
Joined: 03 Sep 2004
Posts: 7
Reply Quote
I think I did not grok what you were suggesting. Sorry to be so dense.

I made the page index.html as my primary page and the code looks like:
:: Code ::
<?php
include('browser_detection_simple.php');

$a_browser_data = browser_detection('full');
$browser = $a_browser_data[0];
$number = $a_browser_data[1];
$os = $a_browser_data[5];
$ie_version = $a_browser_data[2];

if ( ( $ie_version == 'ieMac' ) || ( $browser == 'ns' ) )
{
header("Location: http://ececonsults.com/html/browser.html");
}
?>

and then of course some html which explains what the deal is.
Unfortunately the code is throwing every browser to the browser.html page, except Mozilla Firefox which works fine and shows the index.php .

what have I done wrong?
Back to top
penra
Status: Curious
Joined: 03 Sep 2004
Posts: 7
Reply Quote
It occurred to me that maybe what you said was place that bit of code in the index.php page. So I tried that as well, it doesn't detect Netscape 4.8 on Windows, just takes me to the not so nice looking page.
I can't test with Mac/IE, have to get a pal to do that.

I also thought to try @import ... I can't get that right without using the full url. So it looks like:
:: Code ::
<style type="text/css">@import url("http://domain.com/html/themes/ece/style/style.css");</style>

Should that work also?
The result is that in Netscape 4.8 on windows, the page is still mussed up by bad style translation.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
You didn't do anything wrong, when you redirect a page using php headers the action is instant. You can't redirect them and keep them on the same page, you can do one or the other, but not both. PHP runs on the server, not the user's browser, so all actions must take place there before the page is sent to the user, on the server. All php processing occurs before the user is sent the page html, and no php processing occurs after the page is sent to the user.

It's not necessary to tell the user on the first page, where the redirect is, what's happening, in fact it just confuses them, just redirect them then have on the redirect page they get to a small message telling them they should update their browsers or whatever.

Javascript can redirect after the pages load, but as I said, most users with very old browsers will probably have javascript turned off, so that doesn't help you.

It sounds like Netscape 4.8 supports that @import syntax, that website was slightly inaccurate in that case. Did you say that Netscape 4.8 was not redirected by the script? If so, can you go to the main website, downloads area, and click on the javascript browser detection link upper right and copy the navigator user agent, I don't have netscape 4.8, I'll see if there is a bug in the browser detection script.

If your @import needs the full url you did something wrong, I don't know what, you don't need it, if you use the path /css/yourcss.css for example that needs to be running on a server, whether a development or web hosting server, doesn't matter.

If you try to run that without a server, just as a file, it will go to the root of your drive, if you are on c:\ it will go to c:\ and look for /css/yourcss.css or whatever.
Back to top
penra
Status: Curious
Joined: 03 Sep 2004
Posts: 7
Reply Quote
I am impressed, I think it's working great now but I see a problem with IE 4 on windows, (is anyone still using that?).
take a look at my screen captures I got thru browsercam.com/public.aspx?proj_id=94590

Very cool, huh? What can I add to keep from getting that Moved Permanently on IE4?
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
that's a known IE 4 bug, you can read about it here if you are interested in learning why it happens.

As you can see from the article, this will happen only sometimes, so it's not worth worrying about, and it's not your fault. All this tells you is that on browsercam's servers this bug registered, it might not on another computer. That's by the way the real problem trying to check your pages on these types of services, it's not an actual realworld home / office user setup, so it's only good for rough tests.

When you recommend what browsers people should use, for mac recommend Mozilla Firefox or safari, Firefox is actually better than Safari on OS X. There is no browser option available for OS 9 except very old mozillas, before 1.2 they were making OS 9 versions, still available from Mozilla.org archives or evolt.org browser archives, where you can download almost all the browsers you're currently getting tested on except of course the mac and linux ones.

Because mac IE 5x is actually a pretty modern browser, you shouldn't ask an IE 5x user to upgrade, most of the them are probably using OS 9, and there simply isn't another browser for them to use that is any good, all OS 9 browser development stopped in the last few years.

Mac IE 5x users should simply get the unstyled pages, they will be fully readable, but not styled, we also have a mac ie5x bug on techpatterns main site, but all we do is popup a small message telling them we know about the problem and are trying to fix it, which isn't true :) but at least it makes it look like we care, which we actually don't, since mac ie really is a very bad browser.

Opera [6 is more efficient than 7, but 7 has better css support] is the best browser for slower older windows computers, users should not be advised to download mozilla if they have an older pc or it could crash their system, or be very very slow.

Personally, I don't think it's a good idea creating these redirect pages, I used to do that kind of thing, but now I just serve non compliant browsers straight html, which looks fine, they can read it all, no problem, most people who are using older browsers are using older os's and older pc's and can't really upgrade, but they can read your html if it's well crafted. My sites are all designed to degrade like that, it's by far the easiest and most user friendly method, that's what I would do, you can use browser testing to decide if to write out the css links for example if you want very precise control of who gets it and who doesn't, but I've found that at that point you are talking about a few visitors a month or year, not really worth spending a lot of time on, just give straight html and they will be happy,they are used to it by now.
Back to top
penra
Status: Curious
Joined: 03 Sep 2004
Posts: 7
Reply Quote
thanks very much for your response. I would like to take your suggestion about offering IE5/Mac users straight html. How can I do that?
I do have some OS9 folks that are using a Netscape7 browser so that and the Opera are options. But I agree with your point about asking them to upgrade from IE5, it's an awkward situation.
Back to top
techAdmin
Status: Site Admin
Joined: 26 Sep 2003
Posts: 4127
Location: East Coast, West Coast? I know it's one of them.
Reply Quote
If you use this @import syntax:

@import 'styles.css'

You will not serve stylesheets to the following browsers:

IE 5x mac, NS 4x (unless 4.8 does read that, I'll have to double check that one), or IE 4 windows.

However, I think I can count on one hand how many Netscape 4.8 browsers I've seen on all of my sites in the last 4 years, so that's really not worth worrying about.

All other browsers that come to the site that are not css compliant will be served the plain html, no problems for anyone, no unfriendly change browser pages, it's almost always true now that people using older browsers are using them because they have no choice, so it's best to give them the html and that's all, no older browser will read that @import statement, and no modern non css browser, like dillo, lynx, links, etc will read them either, but all will give your users what they are looking for.

Try evolt.org, the browser section, as jeffd recommended, that's a great resource, download as many as you can, then test your site in real time with real browsers, you'll be amazed at the difference, and how much faster you can develop pages, although from the looks of your page I saw on browsercam, looks like you are pretty decent at getting cross browser css working fairly well.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours