PHP Regex for OS detection

南楼画角 提交于 2019-12-06 16:08:39

You could add a character class after the 1 in the case of OS X Puma that will only match if the character following it is not a digit, e.g.:

'Mac OS X Puma' => 'Mac OS X 10.1[^0-9]',

This should be safe for reliably detecting version 10.1 versus current and future versions, such as Mac OS X 10.1999.42


It should be noted that the user agent strings you are currently matching against have a high probability of being different between browsers, or even editable by users from within their browser. If a high degree of success in matching is necessary, an approach other than user agent sniffing would be needed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!