Search code examples
phpiphoneoptimizationmobile-safari

How do I detect Mobile Safari server side using PHP?


Mobile Safari is a very capable browser, and it can handle my website as it is perfectly. However, there are a few elements on my page that could be optimized for browsing using this device; such as serving specific thumbnails that are smaller than the desktop counterparts to help fit more content into the screen.

I would like to know how I can detect Mobile Safari (all versions, preferably) using PHP, so then I can serve a) a specific css file and b) different sized image thumbnails.


Solution

  • Compare the user agent string with the one of a Safari Mobile uses:

    Safari Mobile User Agent String