How can you differentiate between different browsers using the HTTP_USER_AGENT variable in PHP?

To differentiate between different browsers using the HTTP_USER_AGENT variable in PHP, you can check for specific keywords or patterns that are unique to each browser. This can help you identify the browser being used by the client accessing your website. You can then use this information to customize the content or functionality of your website based on the user's browser.

$user_agent = $_SERVER['HTTP_USER_AGENT'];

if (strpos($user_agent, 'Firefox') !== false) {
    echo 'You are using Firefox browser.';
} elseif (strpos($user_agent, 'Chrome') !== false) {
    echo 'You are using Chrome browser.';
} elseif (strpos($user_agent, 'Safari') !== false) {
    echo 'You are using Safari browser.';
} else {
    echo 'You are using a different browser.';
}