Home

Detect iPhone & iPad in PHP

Oh and this works for the iPod touch as well.  I’m aware that there are great mobile detection solutions out there but I was working with a client recently that has a flash logo animation on their site and unfortunately the source file was unavailable to tweak.  To accomplish this I applied a “simple fix” by using the following code to display alternate content if the visitor is using an Apple device.

<?php
if (preg_match("/iP(hone|od|ad)/i", $_SERVER['HTTP_USER_AGENT'])) {
    // Display iSpecific content
} else {
    // Display other content
}
?>

4 Responses to “Detect iPhone & iPad in PHP”

  1. Boom! Nice!

  2. Very useful. I’ve got a version similar to this getting Vimeo videos to work on the iphone et al.

    • Landon Miller

      Thanks Chris, I will have to check out your vimeo solution!

  3. Nice. I did something similar with javascript to swap HTML5 video tags when iPad is detected.

Leave a Reply