【发布时间】:2014-01-14 22:33:15
【问题描述】:
大家好,我正在使用具有桌面版本和移动后备版本的视频 cms 脚本。用户代理由名为 detect.php 的文件检测,并将用户引导至该站点的桌面版本或移动版本。我创建了一个 webview 应用程序(android 和 ios),其中有广告,因此我希望将移动用户锁定在这些应用程序中,如果他们没有应用程序,则通过重定向他们安装我的应用程序来删除访问权限。我看到了一些建议,但他们没有考虑到混合网站,我担心我最终可能会将使用我的应用程序的人重定向到无限循环中来安装他们已经拥有的应用程序。下面我提供了我的 detect.php 代码...我还查看了谷歌分析并查看了 safari、safari-in-app、android 等。所以我不确定如何采取这种方法,因为涉及的许多因素。
$useragent = $_SERVER['HTTP_USER_AGENT'];
$useragent = trim(strtolower($useragent));
$new_URL = str_replace("www.", '', _URL);
$new_URL_MOBI = str_replace("www.", '', _URL_MOBI);
$current_URL = str_replace("www.", '', "http://".$_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]);
$current_URL_device = strpos($current_URL, $new_URL_MOBI);
$device_url = ($current_URL_device === false) ? 'desktop' : 'mobile';
if ( ! defined('COOKIE_DEVICE'))
{
define('COOKIE_DEVICE', 'melody_device');
}
if(isset($_COOKIE[COOKIE_DEVICE]))
{
if ($_COOKIE[COOKIE_DEVICE] != $device_url)
{
if ($device_url == 'mobile')
{
$takemehome = str_replace($new_URL_MOBI, $new_URL, $current_URL);
header("Location: ".$takemehome."");
exit;
}
elseif ($device_url == 'desktop')
{
$takemehome = str_replace($new_URL, $new_URL_MOBI, $current_URL);
header("Location: ".$takemehome."");
exit;
}
}
}
else
{
if (strpos($useragent, "iphone") !== false || strpos($useragent, "symbianos") !== false || strpos($useragent, "ipad") !== false || strpos($useragent, "nook") !== false || strpos($useragent, "kindle") !== false || strpos($useragent, "IEMobile") !== false || strpos($useragent, "windows phone") !== false || strpos($useragent, "ipod") !== false || strpos($useragent, "android") !== false || strpos($useragent, "blackberry") !== false || strpos($useragent, "samsung") !== false || strpos($useragent, "nokia") !== false || strpos($useragent, "windows ce") !== false || strpos($useragent, "sonyericsson") !== false || strpos($useragent, "webos") !== false || strpos($useragent, "wap") !== false || strpos($useragent, "motor") !== false || strpos($useragent, "symbian") !== false || strpos($useragent, "android") !== false)
{
$device = 'mobile';
setcookie(COOKIE_DEVICE, $device, time() + 84000, COOKIE_PATH);
if (strpos($current_URL, $new_URL_MOBI) === false)
{
//User is NOT on mobile site, redirect
$takemehome = str_replace($new_URL, $new_URL_MOBI, $current_URL);
header("Location: ".$takemehome."");
exit;
}
//Continue as usual
}
else
{
$device = 'desktop';
setcookie(COOKIE_DEVICE, $device, time() + 84000, COOKIE_PATH);
if (strpos($current_URL, $new_URL_MOBI) !== false)
{
//User IS on mobile site, redirect
$takemehome = str_replace($new_URL_MOBI, $new_URL, $current_URL);
header("Location: ".$takemehome."");
exit;
}
//Continue as usual
}
}
?>
【问题讨论】:
-
您实际上没有提供任何相关代码。
-
为什么不重写应用绕过
detect.php页面? -
@Bmargulies 你想要什么代码?
-
@nhgrif 很遗憾我不能这样做,因为我没有为 Windows 和黑莓用户提供应用程序。
-
我添加该评论时根本没有代码。
标签: php android ios jquery-mobile mobile