How do I serve a different page to iPad viewers?
if($_SERVER['HTTP_USER_AGENT'] == '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') {
echo "That is an iPad";
}
See https://developer.apple.com/library/content/technotes/tn2010/tn2262/_index.html
Also, if you're not bothered with an exact match, you might contemplate something like:
if(stristr($_SERVER['HTTP_USER_AGENT'], 'Mozilla/5.0(iPad;')) {
// probably an iPad
}
You can sniff the iPad's user-agent
header via $_SERVER['HTTP_USER_AGENT']
, but ideally, if you can feature-detect the things you want to be different on the iPad vs. any other device, that's more robust and flexible than agent sniffing.
Also, even more simplistic but possibly not as accurate.
if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPad')) {
echo "You are on an iPad";
}
The user agent header in the request will be:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) version/4.0.4 Mobile/7B367 Safari/531.21.10
Notice that it contains "iPad".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With