Detect iPhone & iPad in PHP
April 30th, 2010 4 Comments
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
}
?>

J.P.
Boom! Nice!
Chris Redding
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!
Krystyn
Nice. I did something similar with javascript to swap HTML5 video tags when iPad is detected.