通过手机将选定的桌面Web链接重定向到移动网站

时间:2013-03-08 17:55:34

标签: php redirect mobile hyperlink

我面临一点挑战。我有一个网站,也有移动版本。当使用移动电话的用户点击来自另一个网站(如facebook)的链接时,我希望将用户重定向到显示所选链接内容的移动网站。

成就:

我能够将用户从桌面版本重定向到移动页面。

挑战

我无法显示所选链接的内容,例如http://passnownow.com/inblog.php?id=3840#.UToTf3YetfU.twitter

它只会导航到用户必须搜索帖子的移动网站。

我能做什么。

这是我的代码。

<? include("overall.php");?>
<?

session_start();

require_once('mobile_device_detect.php');

$blackberrystatus = mobile_device_detect(true,true,false,true,true,true,true,false,false);

$androidstatus = mobile_device_detect(true,true,true,true,false,true,true,false,false);

$mobile = mobile_device_detect(true,true,true,true,true,true,true,false,false);
$isMobile = (bool)preg_match('#\b(ip(hone|od)|android\b.+\bmobile|opera m(ob|in)i|windows (phone|ce)|blackberry'.
                    '|s(ymbian|eries60|amsung)|p(alm|rofile/midp|laystation portable)|nokia|fennec|htc[\-_]'.
                    '|up\.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\b#i', $_SERVER['HTTP_USER_AGENT'] );

if($_GET["view"]=="full"){

    setcookie("passnownow[client]", "pc", $time + 1209600);

    $_SESSION["client"] = "pc";

    }

if ($_GET["ref"]=="android" or $_GET["ref"]=="blackberry"){

    setcookie("passnownow[client]", "app", $time + 1209600);

    $_SESSION["client"] = "app";


    header('location: mobile/new.php?id=""');

    } else if ($_SESSION["client"]=="pc" or $_COOKIE['passnownow']["client"]=="pc"){



        }else if ($mobile or $isMobile){

    setcookie("passnownow[client]", "mobile", $time + 1209600);

    $_SESSION["client"] = "mobile";


    **header('location: mobile/new.php?id=""');**   

        }

    include("overall.php");

?>

我的问题是:如何通过header('location: mobile/new.php?id=""');显示所选链接,例如header('location: mobile/new.php?id="234"');

我添加了哪些代码来获取所选链接的网页ID并将其传递给header('location: mobile/new.php?id=""');

我尝试使用$_GET['']命令,但它不起作用,即header('location: mobile/new.php?id=<?php $_GET['id']; ?>');

1 个答案:

答案 0 :(得分:0)

您的重定向语法不正确,这可能是您的问题。您将URL变量视为字符串(例如index.php?var="value")。正确的语法是

header('Location: mobil/new.php?id=1234');

然后在构建字符串时可以执行

header("Location: mobil/new.php?id={$_GET['id']}");

出于安全原因,您应该始终检查输入。

在你的上一次发言中

  

我尝试使用$ _GET ['']命令,但它没有工作,即   标题('location:mobile / new.php?id = <?php $_GET['id']; ?>');

你的问题是当你已经进入PHP时,你正试图进入PHP。当你没有关闭最后一个开头时,无需使用<?php。此外,虽然您的语法已经错误,但您错过了echo

相关问题