Voting

: five minus two?
(Example: nine)

The Note You're Voting On

Paxtez@example
10 months ago
Be careful about using homegrown versions of these.

For example Francesco R's highly rated [ https://www.php.net/manual/en/function.get-browser.php#119332 ] version is no longer correct with Edge:

Current Edge is reporting a string similar to:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0

Note the "Edg/xxx" instead of "Edge"

While it is trivial to update his code to:

<?php
function get_browser_name($user_agent)
{
if (
strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
elseif (
strpos($user_agent, 'Edg')) return 'Edge';
elseif (
strpos($user_agent, 'Chrome')) return 'Chrome';
elseif (
strpos($user_agent, 'Safari')) return 'Safari';
elseif (
strpos($user_agent, 'Firefox')) return 'Firefox';
elseif (
strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
return
'Other';
}
?>

You never know when a value might change in the future.

<< Back to user notes page

To Top