简体   繁体   English

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

[英]redirect selected desktop web link to the mobile site from a mobile phone

I am faced with a little challenge. 我面临一个小挑战。 I have a website and also the mobile version. 我有一个网站,还有移动版本。 When a user using a mobile phone clicks on a link from another site eg facebook, i want the user to be redirected to the mobile site displaying the content of the selected link. 当使用手机的用户单击另一个网站(例如,facebook)上的链接时,我希望将用户重定向到显示所选链接内容的移动网站。

Achievement: 成就:

i was able to redirect the user from the desktop version to the mobile page. 我能够将用户从桌面版本重定向到移动页面。

Challenge 挑战

I am unable to display the content of the selected link eg http://passnownow.com/inblog.php?id=3840#.UToTf3YetfU.twitter . 我无法显示所选链接的内容,例如http://passnownow.com/inblog.php?id=3840#.UToTf3YetfU.twitter

it only navigates to the mobile site where the user will have to search for the post. 它仅导航到用户必须在其中搜索帖子的移动网站。

what can i do. 我能做什么。

this is my code. 这是我的代码。

<? 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");

?>

My question is: how can i pass the header('location: mobile/new.php?id=""'); 我的问题是:如何传递header('location: mobile/new.php?id=""'); to display the selected link eg header('location: mobile/new.php?id="234"'); 显示选定的链接,例如header('location: mobile/new.php?id="234"');

What code do I add to get the page id of the selected link and pass it to header('location: mobile/new.php?id=""'); 我要添加什么代码来获取所选链接的页面ID,并将其传递给header('location: mobile/new.php?id=""');

I tried using the $_GET[''] command but it didn't work ie header('location: mobile/new.php?id=<?php $_GET['id']; ?>'); 我试过使用$_GET['']命令,但是它不起作用,即header('location: mobile/new.php?id=<?php $_GET['id']; ?>');

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" ). 您正在将URL变量视为字符串(例如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']; ?> '); 我尝试使用$ _GET ['']命令,但是没有用,即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. 您的问题是您已经在尝试进入PHP。 No need to use <?php when you haven't closed out of the last opening. 当您尚未关闭上一个开口时,无需使用<?php Also, though your syntax is already wrong, you were missing an echo . 同样,尽管您的语法已经错误,但是您缺少echo

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM