0

我面临一个小挑战。我有一个网站,还有手机版。当使用移动电话的用户单击来自另一个站点(例如 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']; ?>');

4

1 回答 1

0

Your syntax for your redirect is incorrect and this may be your problem. You're treating the URL variable as a string (ex. index.php?var="value"). The proper syntax would be

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

Then when building your string you can do

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

You should always check your inputs for security reasons.

In your last statement

I tried using the $_GET[''] command but it didn't work ie header('location: mobile/new.php?id=<?php $_GET['id']; ?>');

Your problem was that you were trying to enter into PHP when you were already in it. No need to use <?php when you haven't closed out of the last opening. Also, though your syntax is already wrong, you were missing an echo.

于 2013-03-08T18:05:30.820 回答