Reputation: 135
I need to limit what browsers can user use to view on my page. I want to allow only Chrome, FireFox 4+ and all WebKit based browsers. If user use i.e. explorer, PHP will produce output i.e.: "You have not supported browser, use Chrome, Firefox 4+ or WebKit based browser!" How can I do it?
Upvotes: 0
Views: 1437
Reputation:
$_SERVER['HTTP_USER_AGENT']
will give you browser details, and from that you can work your way up to verification good luck
This may be so lame, since I am PHP newbie but, I would check if someone is using Mozilla (firefox) by doing this:
$browser = $_SERVER['HTTP_USER_AGENT'];
if (strpos($browser,'Mozilla') !== false) {
echo 'You are using Mozilla';
} else {
echo 'You are not using Mozilla';
}
Upvotes: 1
Reputation: 29434
Use $_SERVER\['HTTP_USER_AGENT'\]
or get_browser()
.
But you should really ask yourself why this is necessary. If your site doesn't work with all feature, than it's ok to show a message saying:
Please upgrade your browser in order to use all features.
You can also detect whether specific JS functions/objects exists so you won't run into Undefined identifier
errors (credits to epascarello).
Upvotes: 1
Reputation: 16117
PHP sniffer is a library that handles extracting information about the user and user-agent (browser).
It uses the same data that get_browser()
or $_SEREVER['HTTP_USER_AGENT']
can give you but it formats it into a nicely structured object that you can use in your code.
Upvotes: 1
Reputation: 8889
You can check server variable:
<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>
Upvotes: 0