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.
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 .
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=""');
to display the selected link eg 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=""');
I tried using the $_GET['']
command but it didn't work ie 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"
). 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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.