+4 votes
in Programming Languages by (6.3k points)
I want to store the name of the browser that a visitor used to access my website.

How can I find the browser of visitors using PHP code?

2 Answers

+1 vote
by (25.6k points)

You can use the reserved variable $_SERVER to check the user agent. The user agent will give you the name of the browser.

Here is a sample PHP code to check the browser name.

<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE || strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE)
    echo 'You are using Internet Explorer.<br />';
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE)
    echo 'You are using Chrome.<br />';
elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE)
    echo 'You are using Firefox.<br />';
else
    echo 'Unknown browser.<br />';
?>

0 votes
by (160 points)
edited by
...