Hi there, folks. Although this is my first post, I regularly follow Sitepoint articles on the RSS Feed. Also I have more or less learned what I know about PHP from reading countless threads on this forum (and the PHP Manual, of course). Knocking my head gently on the desk sometimes helps.
I felt the need to register and post because of a problem I have with Apple Safari persistently spoofing Internet Explorer on Windows XP. It makes no difference whether I have the browser's user agent set to default (Automatically chosen) or specifically Safari 5.0.3 - Windows. The browser still behaves as if it were Internet Explorer. Perhaps the problem may be down to how I handle browscap.ini but the argument in the code block below works fine for Firefox, Chrome, Opera and Explorer.
I use the following to detect the user agent and set a patch of javascript if the visitor is using Explorer on a desktop computer:
Basically, I am wondering if there might be a more specific way to query browscap that will unmask the Apple browser?Code php:if ($configure == 'desktop') { require_once('Content_Arrays.php'); $explorer = null; $array = new Content_Arrays(); $jss = ($array->sup); if (!isset($_COOKIE['support'])) { $browser = get_browser(null, true); if (($browser['browser'] = 'MSIE') && ($browser['version'] < 9) || ($browser['browser'] = 'Firefox') && ($browser['version'] < 3.5) || ($browser['browser'] = 'Opera') && ($browser['version'] < 7) || ($browser['browser'] = 'Safari') && ($browser['version'] < 3)) { $explorer = 1; $support = $jss[1]; } else { $explorer = 0; $support = $jss[0]; } setcookie('support', $explorer, time()+3600, '/', 'www.example.com', 0, 1); return $support; } }
Note: I understand that user agent detection is an imperfect solution but I prefer the method to using javascript for client-side detection. The exception here is a patch to support CSS media queries in older versions of Explorer.



Reply With Quote
Bookmarks