Jump to content

Add referrer URI to desitnation URL string


Stefan83

Recommended Posts

I'm using the mobiledetect.net script to redirect mobile users to a mobile page. I'd like to dynamically add the referrers URI to the URL string ie /?source=previous-page. For example, when visiting http://mainsite.com/landing-page you are redirected to http://www.mobiledomain.com/?source=previous-page

Is this possible?
 

<?php
@include("Mobile_Detect.php");
$detect = new Mobile_Detect();

if ($detect->isMobile() && isset($_COOKIE['mobile']))
{
$detect = "false";
}

elseif ($detect->isMobile())
{
header("Location:http://www.mobiledomain.com/");
}
?>
Link to comment
Share on other sites

Not sure but maybe

$source = '';
if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/')
   $source = '?source=' . $_SERVER['REQUEST_URI'];
header("Location:http://www.mobiledomain.com/$source");

Now $_GET['source'] will contain the request url before being redirected to your mobile site.

Edited by Ch0cu3r
Link to comment
Share on other sites

You'll want to urlencode the url in the query string.

$source = '?source=' . urlencode($_SERVER['REQUEST_URI']);
just in case there are any "special" characters in it.

 

Do you want the url of the page that is doing the redirect (which is what Ch0cu3r's code gives you)? Or do you want the url of the the page they came from to get to the page that is doing the redirect? In the second case, use $_SERVER['HTTP_REFERER'] instead of 'REQUEST_URI'.

Link to comment
Share on other sites

That's great, thanks guys. Almost there, but it returns ?from= twice and the current page in the string as well.

 

So the URL for the landing page is http://mobiledomain.com/mobile/?from=%2Fmobile%2F%3Ffrom%3D%252Fpassengers%252Ftaxybikes%252F

 

My code is

<?php
include('Mobile_Detect.php');
$url = get_bloginfo('url');
$detect = new Mobile_Detect();

if ($detect->isMobile() && isset($_COOKIE['mobile']))
{
$detect = "false";
}

elseif ($detect->isMobile())
{
$source = '';
if(isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/');
   $source = '?from=' . urlencode($_SERVER['REQUEST_URI']);
header("Location:http://mobiledomain.com/mobile/$source");

}
?>

ANy ideas why that is?

 

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.