0

could you please tell me that how do I implement a Update Your Browser notification in php? Actually I'm developing a web app, which is fully done with html5, so I wanna show a notification to those users, who does not have an updated browser, so that they can update their browser. Waiting for your reply.

Thanks

iSaumya
  • 1,503
  • 5
  • 21
  • 50
  • 2
    If you don't mind doing it with javascript, http://browser-update.org/ has an easy to use one – dave Jul 09 '13 at 22:47
  • 2
    I suggest using a feature detection library like [Modernizr](http://modernizr.com/). – showdev Jul 09 '13 at 22:47
  • 3
    +1 to Modernizr. Detect features, not browser – z1m.in Jul 09 '13 at 22:49
  • I hate sites that tell me what i should be using, why don't you learn to write compatible code –  Jul 09 '13 at 22:53
  • because some things are just not possible with the old browsers, Dagon. The developer could only create an app if he would work with older standarts, and these have other negative aspects e.g. being bound to a certain OS ...EDIT after checking your profile I think you have way more experience than me so would you mind to explain to me how your ideal is possible to follow? – lucidbrot Jul 02 '15 at 20:50

2 Answers2

1

As others have noted, using JS to check for the feature you need in the browser is best. But if you must do it on the server, your php could check the $_SERVER['HTTP_USER_AGENT'] string for details. For example:

Here is the request from my Mac:

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5 Safari/536.30.1

And here from my Windows server:

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
bitfiddler
  • 2,095
  • 1
  • 12
  • 11
1

You can check the browser version by using the PHP User Agent

if($_SERVER['HTTP_USER_AGENT'] == 'Firefox (or whatever)'){
    echo 'Please update your browser.';
}

A better way to do it would be by checking the version of their browser. To do this, first, use get_browser:

 $users_browser = get_browser(null, true);

Then, do the same thing as above, but use the version element:

if($users_browser[version] == 1.0.4){
    echo 'Please update your browser.';
}

This would take some time, and testing, on your part, to find which browsers ad versions work. Then, you could double-check:

 if($_SERVER['HTTP_USER_AGENT'] == 'Firefox'){
    if($users_browser[version] <= 0.9){
        echo 'Please update your browser.';
    }
}

This would display the error to anyone using Firefox version 0.9 or earlier.

I hope this helps.

Noah T
  • 235
  • 4
  • 12