PHP Detect Browser
How can I detect browser using php.You can use php server variable $_SERVER[‘HTTP_USER_AGENT’] for this.It will return about the user’s operating system, as well as their browser.It contents of the User-Agent header from the current request.
So simply you can echo this for more understand.
echo $_SERVER['HTTP_USER_AGENT']; //Output Mozilla/5.0 (Windows NT 6.1; rv:14.0) Gecko/20100101 Firefox/14.0.1
Usage:
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE){
echo 'Internet explorer';
}
else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE){
echo 'Mozilla Firefox';
}
else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) {
echo 'Google Chrome';
}
else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE) {
echo 'Safari';
}
else {
echo 'Something else';
}
You can check iPad like this.
private function ipad_request() {
return isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'iPad');
}
What's your reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0





