• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirecting to mobile url issue

#1
Hi guys. I have an issue with redirecting mobile users to mobile url.

Define('MOBILE_URL_RAW', 'm.mysite.tld');

in __construct() of core/MY_Controller.php i have this following code:

if($this->detect->isMobile()){
$url = parse_url($_SERVER['REQUEST_URI']);
if($url["host"] != MOBILE_URL_RAW){

redirect(str_replace(MOBILE_URL_RAW, $url["host"], $url));
}
}
i also tried:
if($this->detect->isMobile() && $_SERVER["HTTP_HOST"] != MOBILE_URL_RAW){

redirect(str_replace(MOBILE_URL_RAW.$_SERVER['REQUEST_URI']);
}

but it seems not to work because the requested page keeps refreshing till it says 'couldnt get page' .
How to make it work?
Be Simple Angel
Reply

#2
so nobody to help me out? Not even a single push for me?
Be Simple Angel
Reply

#3
I can't say I have an answer but this might be a problem.

Quote:'REQUEST_URI'
The URI which was given in order to access this page; for instance, '/index.html'.

So parse_url will return something like
Code:
Array ( [path] => /index.html ) 1

So you pass this test here:
Code:
if($url["host"] != MOBILE_URL_RAW){

And do this command
Code:
redirect(str_replace(MOBILE_URL_RAW, $url["host"], $url));

And since MOBILE_URL_RAW is not found, you are redirecting back to the original calling url.

I think the logic is flawed, but am suprised you do not get an error thrown, so perhaps I am wrong.

Hope  that helps,

Paul.

PS Perhaps something like: (not tested or used, just playing about as bored at mo)

PHP Code:
Define('MOBILE_URL_RAW''m.mysite.tld');

if(
$this->detect->isMobile()){
       if(
$_SERVER['REQUEST_HOST'] != MOBILE_URL_RAW){
              
redirect(MOBILE_URL_RAW.'/'.$_SERVER['PATH_INFO']);
       }

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme ¬© 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.