2013-03-08 42 views
0

我面臨一個小小的挑戰。我有一個網站,也是移動版本。當用戶使用手機點擊另一個網站(例如Facebook)的鏈接時,我希望用戶被重定向到顯示所選鏈接內容的移動網站。將選定的桌面網頁鏈接重定向到移動網站從手機

成就:

我能夠從桌面版本的用戶重定向到移動網頁。

挑戰

我無法顯示選定的鏈接e.g 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']; ?>');

回答

0

您的重定向語法不正確,這可能是您的問題。您將URL變量視爲字符串(例如index.php?var="value")。正確的語法是

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

然後建立您的字符串時,你可以做

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

您應經常檢查您輸入出於安全原因。

在你的最後一句話

我嘗試使用$ _GET [ '']命令,但它沒有工作即 頭( '位置:移動/ new.php ID = <?php $_GET['id']; ?>'?);

你的問題是,當你已經在它試圖進入PHP。如果您沒有關閉最後一次開放,則無需使用<?php。另外,雖然你的語法已經錯了,但你錯過了echo

相關問題