Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 633
different Avatar asked Oct 09 '08 10:10

different


People also ask

How do I check if a website is open in mobile or desktop PHP?

An easy way to detect a mobile or desktop device in PHP is to check if the HTTP user agent contains the word “mobile”. $ua = strtolower($_SERVER["HTTP_USER_AGENT"]); $isMob = is_numeric(strpos($ua, "mobile"));

What is Mobile Safari?

Safari is the best way to experience the internet on all your Apple devices. It brings robust customization options, powerful privacy protections, and industry-leading battery life — so you can browse how you like, when you like. And when it comes to speed, it's the world's fastest browser.


1 Answers

Thanks Joe, I read that page and found the WebKit detection library (in JavaScript). I changed the code to suit my needs.

For anyone that's interested, here's my solution.

<?php

/* detect Mobile Safari */

$browserAsString = $_SERVER['HTTP_USER_AGENT'];

if (strstr($browserAsString, " AppleWebKit/") && strstr($browserAsString, " Mobile/"))
{
    $browserIsMobileSafari = true;
}

?>
like image 76
different Avatar answered Sep 30 '22 02:09

different