+4 votes
in Programming Languages by (59.8k 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

+2 votes
by (353k points)
selected by
 
Best answer

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 />';
?>

+1 vote
by (180 points)
edited by

Related questions


...