SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: Trouble getting browscap.ini to tell Safari from Internet Explorer

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    Republic of Ireland
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble getting browscap.ini to tell Safari from Internet Explorer

    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:
    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;
                    }
                }
    Basically, I am wondering if there might be a more specific way to query browscap that will unmask the Apple browser?

    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.
    Last edited by Enver; Oct 6, 2012 at 11:14. Reason: Typo in Summary

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •