Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect if browser is firefox with php? [duplicate]

Tags:

php

Possible Duplicate:
Any php code to detect the browser with version and operating system?
how to detect internet explorer and firefox using PHP?

I need to add specific html to non firefox browsers, therefore I need to first detect if user is using firefox or not, i have to do this using php. Something along these line?

<!--[if Firefox]>
Mozilla only HTML here!
<![endif]-->

Any one? Thanks

like image 920
rob.m Avatar asked Nov 29 '22 03:11

rob.m


1 Answers

Use this snippet of code to retrieve the kind of browser:

if (isset($_SERVER['HTTP_USER_AGENT'])) {
    $agent = $_SERVER['HTTP_USER_AGENT'];
}

Then, compare against the user agent string.

For example, to detect "Firefox" you could do:

if (strlen(strstr($agent, 'Firefox')) > 0) {
    $browser = 'firefox';
}
like image 184
DonCallisto Avatar answered Dec 18 '22 22:12

DonCallisto