dqxuiq7772 2013-11-04 09:20
浏览 47

PHP - iPad或iPhone检测无法使用strstr和$ _SERVER ['HTTP_USER_AGENT']

I have an app which posts a status update with a link onto a users facebook wall. If anyone then clicks on the link in the status they need to be redirected to the relevant page based on whether they are viewing on an iPhone, ipod, iPad or PC/Mac

So my php code in my link page is:

<?php
if(strstr($_SERVER['HTTP_USER_AGENT'],'iPod') || strstr($_SERVER['HTTP_USER_AGENT'],'iPhone')) {
    header('Location: iphone app redirect...');
}
else if(strstr($_SERVER['HTTP_USER_AGENT'],'iPad')) {
    header('Location: ipad app redirect...');
}
else {
    header('Location: website link redirect');
}
?>

Problem is that it is picking up the iPhone and website redirect correctly but not the iPad. When on iPad it takes you to the iPhone link.

I've checked the output for the user agent as i wasnt sure whether coming from facebook might mean it doesn't send it correctly but on an iPad and it comes out with:

Mozilla/5.0 (iPad; CPU OS 7_0_2 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A501 Safari/9537.53

So the strstr should surely pick up the iPad?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Qt下使用tcp获取数据的详细操作
    • ¥15 idea右下角设置编码是灰色的
    • ¥15 全志H618ROM新增分区
    • ¥20 jupyter保存图像功能的实现
    • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示
    • ¥15 NAO机器人的录音程序保存问题
    • ¥15 C#读写EXCEL文件,不同编译
    • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
    • ¥15 扩散模型sd.webui使用时报错“Nonetype”
    • ¥15 stm32流水灯+呼吸灯+外部中断按键