1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP Script To Redirect Users Based On Their Browser

Discussion in 'PHP' started by NeverTheSame, Apr 4, 2010.

  1. roopajyothi

    roopajyothi Active Member

    Messages:
    1,302
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    80
    #21
    Nice! but what will you do for Mobile Symbian OS Browsers they are taking a major role :)
    SEMrush
     
    roopajyothi, May 12, 2010 IP
    SEMrush
  2. DAFFY555

    DAFFY555 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #22
    Hi,

    Firstly this is a fantastic browser redirect .php code. Secondly, I'm quite curious as to how I might go about making it IE6, 7, and (8/9) specific on the redirect. Rather than just MSIE redirect. Which will re-direct 5, 6, 7, 8 and 9 to my desired page. etc.

    Thank you for your time and help.
     
    DAFFY555, Jan 13, 2012 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    25,254
    Likes Received:
    3,438
    Best Answers:
    100
    Trophy Points:
    665
    #23
    Seriously - you have a different version of your page based on that level of detail?

    Are you sure it wouldn't be better handled by just changing a part of the page depending on the browser? And use browser hacks to make the page look right?

    BTW use IETester to view your site in the different versions.
     
    sarahk, Jan 13, 2012 IP
  4. DAFFY555

    DAFFY555 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #24
    Thank you Sarahk for your reply.

    I know it sounds excessive. Basically the website uses HTML5 on the home page, I've got the site setup so it redirects to Safari with a .mp4 video instead of the .ogv which plays in Chrome, Opera and Firefox. But my problem is, I would like it really so I could have it re-direct to IE 9 and then a specific page for IE 8 & 7, then another with anything from IE 6.0 and below to direct to a specific page that fits that browsers capabilities. My client is really rather picky, and dosen't seem to understand the complications with IE6 these day. Though I am currently re-editing part of the css for the website to suit IE 6, which should be done by tomorrow, and therefore shall only work when IE6 is detected. This only relates to the .png images in terms of the transparency issues, which can be found with IE6. etc.

    The website is http://ArcticRabbit.com

    At the moment:

    Chrome, Firefox and Opera: /HOME/

    Safari shall go to: /HOME-Safari/

    MSIE: /HOME-IE6and7/

    As the MSIE version is a static picture with a link rather than video on IE7 + my client isn't happy. And thus wants it to have the video working on IE7 and above. Though obviously IE7 & 8 work differently with video, and I have been testing out this with it, though as you would expect it isn't as user friendly, though what would you expect I guess.

    <object>
    <embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/windows/windowsmedia/default.aspx"
    width="898" height="430" src="http://arcticrabbit.com/MEDIA/ARP-Ident.mp4"
    showcontrols="True" showstatusbar="False"
    showdisplay="False" autorewind="True"
    wmode="transparent"
    AutoStart="True">
    </embed>
    </object>

    and IE 9 is a lot easier and less tedious with HTML5 support, when implementing it into the site I find. Though obviously the other option for the above is to of course use flash. Though, anyone whom has IE7 and below is very unlikely to be one to update their software and applications often. Thus that could a snag, in compatibility. And most IE6 user are used to not having all content working, which is why that must be static. So to create the best and most professional image/experience possible.

    Also another issue, I actually just noticed is Chrome on Windows. Thus I need a re-direct for that also I think, within the same php.



    I've been using Adobe Browser Labs mainly, and BrowserShots. 'Mac' user. lol As well as a not so new Windows Samsung Laptop.


    Thanks for you help.
     
    DAFFY555, Jan 13, 2012 IP
  5. sarahk

    sarahk iTamer Staff

    Messages:
    25,254
    Likes Received:
    3,438
    Best Answers:
    100
    Trophy Points:
    665
    #25
    That's fair enough but have you looked at the traffic stats to see if IE6 is actually being used?

    I just looked at my busiest site and IE is used on 56% of visits but when I drill down and look at IE6 its only 3% of the IE visits. The "return on investment" will be minimal if I spent my client's money focusing on those laggards.

    In the meantime I'd boot up IETester with a test page that just echo's out $_SERVER ['HTTP_USER_AGENT']) and see what the differences are and build that into your switch statement
     
    sarahk, Jan 14, 2012 IP
  6. madesignuk

    madesignuk Greenhorn

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    21
    #26
    Thanks for this code snippet, just had a similar need where the differences between Chrome, FF and IE do't stack up, and a simple ccs coding doesn't do the job anymore, so a dedicated HTML page has had to be created for not only Browser, but display sizes so as to cover 4:3 16:9 ratio screens...

    Anyway, using your example, I have developed the php to provide feedback for browser type, build and screen resolution.

    Hope you find this adaptation of use, if anyone improves on it, welcome the improvements as only spent 1hr on this so haven't had the opportunity to specify all the options for the many browser types - so currently is only developed fully for Chrome, IE and FF

    enjoy::


    // Start of code snippet /////////////////////////////////////////////////////////////////////////////
    // Code SNIPPET :: Source :: http://stackoverflow.com/questions/6660649/mobile-or-desktop-browser-detection-and-redirect-to-respective-web-page
    // Added 14 0220
    // need to identifly different browsers so as to display correct Window/Div sizing!
    
        $USER_AGENT = explode('/', $_SERVER ['HTTP_USER_AGENT']);
        
          print_r ($USER_AGENT);
          echo "\n\n";
         
        /* Eliminate IE */
        if (strpos($USER_AGENT[1], 'MSIE') !== false ){
           //  echo "Browser => TEST";
        }
        
        $browserDetect = explode (" ",$USER_AGENT[2]);
        //print_r ($browserDetect);
        // Need to swop around the Keys so that the Browser is the first key in the array - makes things easier with detecting
        $browserDetect = array_reverse ($browserDetect);
        //print_r ($browserDetect);
       
         /* Redirection */
        switch ($browserDetect[0]) {
            case 'Mozilla' :
            echo "Browser => Mozilla";
            break;
            case 'Chrome' :
            echo "\nBrowser => Chrome";
            // build =
            $browserBuild = explode (" ",$USER_AGENT[3]);
            echo "\nBuild => ".$browserBuild[0];
            break;
            case 'Firefox' :
            echo "Browser => Firefox";
            // build =
            echo "\nBuild => ".$USER_AGENT[3];
            break;
            case 'Gecko' :
            echo "Browser => IE";
            // build =
            $browserBuild = explode (" ",$USER_AGENT[2]);
            echo "\nBuild => ".$browserBuild[2];
            break;
            case 'Opera' :
            echo "Browser => Opera";
            break;
            case 'Googlebot' :
            echo "Browser => Googlebot";
            break;
            case 'msnbot' :
            echo "Browser => msnbot";
            break;
            case 'Safari' :
            echo "Browser => Safari";
            break;
            default :
            echo "Browser => Unsure what browser your using?";
            break;
        };
    // Added 14 0220 /// Source::     http://en.kioskea.net/faq/1251-php-detect-the-display-resolution
    // Needed to set the Viewer Screen for FF and IE
    
        if(!isset($_GET['r']))    
        {    
        echo "<script language=\"JavaScript\">    
        <!--     
        document.location=\"$PHP_SELF?r=1&width=\"+screen.width+\"&Height=\"+screen.height;    
        //-->    
        </script>";    
        }    
        else {        
    
        // Code to be displayed if resolutoin is detected    
             if(isset($_GET['width']) && isset($_GET['Height'])) {    
                   echo "screen size: ".$_GET['width']."x".$_GET['Height'];
             }    
             else {    
                    // Resolution not detected    
             }    
        }    
    // End of code snippet /////////////////////////////////////////////////////////////////////////////
    PHP:
     
    madesignuk, Feb 20, 2014 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,630
    Likes Received:
    724
    Best Answers:
    152
    Trophy Points:
    470
    #27
    Different screen ratios? Really? Even so, that can be solved with @media-queries directly in CSS - no need to sniff browsers for that.
    And for the IE6-client. Inform your client that IE6 is no longer even supported from MS, and should NOT BE CATERED FOR.
    Or, better yet, tell the client he's wrong, and refuse to spend time creating bloated code-solution for something that shouldn't be an issue. People still using IE6 gets told they need to f*cking upgrade, and that's it. Simple.
    I'm no longer really in the game of developing public websites, but it's quite simple: just tell the client that you will implement support for FF, Chrome, Safari, Opera and IE, but only IE 11,10, 9 and maybe 8 - anything older than that will have to deal with whatever issues shows up, if the client wants "fancy stuff". Of course, fix what can be fixed, but don't spend hours fixing broken software of which you have no control.
     
    PoPSiCLe, Feb 20, 2014 IP
  8. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #28
    I was just about to suggest the switch for performance and tidiness. I personally would use preg_match() and avoid UNDEFINED VARIABLE issues though....

    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
        $USER_AGENT = explode('/', $_SERVER['HTTP_USER_AGENT']);
    } else {
        $USER_AGENT = 'MSIE'; // default to show if no agent sent.
    }
    PHP:
    also instead of using isset() you should be using !empty()

    if(!empty($_GET['width']) && !empty($_GET['Height'])) { 
    PHP:
     
    DomainerHelper, Feb 20, 2014 IP
  9. madesignuk

    madesignuk Greenhorn

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    21
    #29
     
    madesignuk, Feb 21, 2014 IP
  10. madesignuk

    madesignuk Greenhorn

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    21
    #30
    Point understood, but have been developing css sites since 1997, so know all the limitations. But many "manufacturing" company's may use new technology in the works process, but when it comes to office/ admin software - many still rely on what we would consider obsolete s/w, using WORD/ OFFICE 2003, NT XP and IE 6 and 7 etc, Why - Because it works, Works well and does its Job!
    Furthermore the fact that it is outdated, doesn't mean it cannot still do its job. In many cases the reverse is so true.

    I myself, code using NotePad, that dates from 1992, it works, does the job, rarely crashes etc etc.
    Above all it applies to the KISS mode of working.

    So different screen sizes - Yes, in this case we need to have the ability to READ the different screen sizes, due to the BUGS in Chrome FF and IE all to do with the different interpretations of the BOX model (still) and 100% scaling of divs within divs, and the use of a sticky footer. Chrome is the most accurate rastering of CSS5 WC3 code, whereas IE & FF still do their own and very weird things.

    In this case the screen sizes are taken using JS, then set as a php variable, all to set the size of a div within a fluid layout, that works GREAT in Chrome, but FF & IE, does not know what a 100% of a display area is still??

    So I haven't been trying to fix OLD s/w that I have no control over, its the latests Browser versions that still do their own things, regardless of WC3 so called conventions. Thought quirky mode was dead and buried, but still keep on finding its ghosts.
     
    madesignuk, Feb 21, 2014 IP
  11. madesignuk

    madesignuk Greenhorn

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    21
    #31
     
    madesignuk, Feb 21, 2014 IP
  12. madesignuk

    madesignuk Greenhorn

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    21
    #32
    Thanks for this UPDATE
    Will implement, was as said put this together in an hour or so, so used code snippets, which worked. But, as you have pointed out there are always alternative ways of doing things, each with its own merits.

    thank you
     
    madesignuk, Feb 21, 2014 IP
    DomainerHelper likes this.
  13. deathshadow

    deathshadow Acclaimed Member

    Messages:
    8,975
    Likes Received:
    1,635
    Best Answers:
    233
    Trophy Points:
    515
    #33
    Nothing like a bump of a four year old topic filled with idiotic nonsense that has NO business being done on a website in the first place! Anyone DUMB ENOUGH to pull stupid stunts like browser sniffing (and that's the proper term for this) needs to do the world a favor, back the **** away from the keyboard, and not come back until they know how to do it without such idiocy and ineptitude.

    If you need to sniff out what browser is running -- client side or server-side -- as opposed to capabilities detection -- you don't know enough about HTML, CSS or server-side languages like PHP to be doing anything relating to web development!
     
    deathshadow, Feb 21, 2014 IP
  14. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #34
    deathshadow, you really need to get laid... take anger management classes in the least. You haven't stopped to think that there MIGHT have been a good reason for someone to want to do this and really if this bothers you... the bump or the post content... you really need help.
     
    DomainerHelper, Feb 21, 2014 IP
  15. deathshadow

    deathshadow Acclaimed Member

    Messages:
    8,975
    Likes Received:
    1,635
    Best Answers:
    233
    Trophy Points:
    515
    #35
    What? You're still supporting IE5?!? There are no "different interpretations of the box model" worth mention -- if you're having problems you likely either don't have a doctype, or just don't know what you are doing. (probably still sleazing out 1997 style HTML 3.2 and slapping 4 tranny of 5 lip-service around it too!)

    Not sure what that even means, though I would suspect things like equal-width equal-height boxes, which have no business on a website in the first place.

    If you mean always on screen, see "shit that doesn't belong on a website", if you mean a 100% min-height layout, it's not rocket science if you can fix the footer height. If you can't fix the footer height, these days I say use flex-box and then "who gives a ****" if it's not flush at the bottom on IE9/earlier. It's too easy to get obsessed on being "perfect" on older browsers. Someone can't join us in THIS century give them a degraded but fully functional page. They ask "why" you tell them "because you still have your head wedged up the previous decade's backside!"

    I hope that's dyslexia, since there is no such thing as CSS5 and I'm not sure what Commander Blair, Angel and Paladin have to do with anything.

    Though I will concede you that point -- but browser sniffing is NOT the answer. admittedly, I don't think IE conditional comments are the answer either.

     
    deathshadow, Feb 21, 2014 IP
  16. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #36
    lol, cries about the thread age and still won't let it die.
     
    DomainerHelper, Feb 21, 2014 IP
  17. deathshadow

    deathshadow Acclaimed Member

    Messages:
    8,975
    Likes Received:
    1,635
    Best Answers:
    233
    Trophy Points:
    515
    #37
    Sorry, but seeing the same mistakes made year after year, and now decade after decade wears really thin -- especially when it's about promoting ineptitude and outright broken methodology. History bears this out -- from "bork bork bork" to "BoA + Opera 10 = Opera 1.0" to Compass vs. FF, vs every other time browser sniffing has resulted in a website ending up being the equivalent of CENTER + FONT... "two tags, one cup".

    Though I have zero tolerance for the whole namby pamby limp wristed "if you can't say anything nice" asshattery. Status quo FTMFW is no way to have actual progress or make anything better; that trash can go right back where it belongs around the drum circle with everyone singing kumbaya. Slapping the rose coloured glasses on everyone's heads to lead them down the garden path is NOT the path to doing things properly, efficiently, or having anything remotely resembling improvement! No, I don't want to buy a pencil! ... and if I did I'd sharpen it in your...

    If anyone is butthurt over anything I say, they probably needed to be butthurt and take a good long look in the mirror... and MAYBE call the orthodontist to help extract their head from 1997's backside... since to be frank, if you don't grasp what I've said you're most likely tonguing the 1990's tonsils the same long route Lemmiwinks had to take.

    That's because there isn't one if you care about accessibility, and use good programming practices like semantic markup, separation of presentation from content, and progressive enhancement -- giving you device neutrality, accessibility and graceful degradation.

    I call halfwit BS halfwit BS when I see it. I'm sick to death of all these inaccessible slow loading broken script-tard websites that are less useful than the web was 20 years ago, taking longer to load on 45mbps fiber than the same content would have taken at 56K back then... and it's buggy broken non-future-proof nonsense like this entire topic that causes them.

    Or as George Bernard Shaw put it:
    "The reasonable man adapts himself to the world: the unreasonable one persists in trying to adapt the world to himself. Therefore all progress depends on the unreasonable man."

    Beware of the man who does not return your blow: he neither forgives you nor allows you to forgive yourself.
     
    Last edited: Feb 21, 2014
    deathshadow, Feb 21, 2014 IP
  18. deathshadow

    deathshadow Acclaimed Member

    Messages:
    8,975
    Likes Received:
    1,635
    Best Answers:
    233
    Trophy Points:
    515
    #38
    Calls laughing at it "crying about it" -- comprehension, try it.
     
    deathshadow, Feb 21, 2014 IP
  19. DomainerHelper

    DomainerHelper Well-Known Member

    Messages:
    445
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    100
    #39
    Ok cupcake.
     
    DomainerHelper, Feb 21, 2014 IP