我有一个移动网站,我正在将移动用户从主网站重定向到移动网站。但我也在我的移动网站上给出了一个选项,如果一些移动用户想要访问主网站,他可以。为了解决这个问题,我在我的主网站上写了这段代码
if (is_mobile()== true) //if user is browsing from mobile
{
$main_website_url= 'http://localhost/www/redsignal/'; // main website URL
$mobilesite_url = 'http://localhost/www/redsignal-mobile/'; //mobile website URL
$mobilesite_url_length = strlen($mobilesite_url);
$referring_path_url = substr($_SERVER['HTTP_REFERER'], 0 , $mobilesite_url_length);
if ($referring_path_url == $mobilesite_url) //This if condition checks that if the mobile user is coming from my mobile website or not
{
header("Location:".$main_website_url); // if he is coming from mobile he will be redirected to main website
}
else
{
header("Location:".$mobilesite_url); // if not than he will be redirected to mobile website
}
}
答案 0 :(得分:1)
您需要使用另一个变量,以便在点击访问移动网站中的原始网站时区分是否要强制显示原始网站。为此,你可以传递GET变量,例如
http://localhost/www/redsignal/?force_show_original=1
然后在您的代码中更改此
if (is_mobile()== true)
到
if (is_mobile()== true || $GET["force_show_original"] == true)
让我知道它是否有效
<强>更新强>
使用以下代码重定向网站
if (is_mobile()== true || $GET["force_show_original"] == false) {
//redirect to mobile site
}
else if(is_mobile()== true || $GET["force_show_original"] == true) {
// redirect to original site
}
else {
// redirect to original site
}
答案 1 :(得分:-1)
如果标头不起作用,则可以使用javascript进行重定向,如
echo "<script type='text/javascript'> document.location.href='$main_website_url'</script> ";