I have been doing a lot of iPhone website development lately. There are lots of tips and tricks I have found to making websites look proper on these devices. I’ll separate some of these tricks into different articles.
The HTTP_USER_AGENT for an iPod Touch (my iPod Touch anyway) is:
Mozilla/5.0 (iPod; U; CPU iPhone OS 3_1_3 like Mac OS X; en-us) ---> AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7E18 Safari/528.16
ipad is:
Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) ---> AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10
so in PHP if you just search for “iPhone” in the HTTP_USER_AGENT you can see if it is indeed a small mobile device coming to your website:
if(stripos($_SERVER['HTTP_USER_AGENT'], "iphone") > 0) {
echo "This is an iphone!";
}
else {
echo "NOT an iphone!";
}