I created a mobile version of a client's website. I created a subdomain called mobile.sitename.com

In the past I have used this code on the index.php page:

<?php $mobile = "http://mobile.cogistix.com";
if(preg_match('/Windows CE/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match("/iphone/i",$_SERVER["HTTP_USER_AGENT"])) { header("location: $mobile");}
elseif(preg_match('/Blackberry/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/PalmOS/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/PalmSource/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/SymbianOS/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Opera Mini/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Nokia/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Samsung/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/vodaphone/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/Jphone/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/AvantGo/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/DoCoMo/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
elseif(preg_match('/DDIPOCKET/i',$_SERVER['HTTP_USER_AGENT'])) { header("location: $mobile");}
?>

It usually works great. But this time when I try to bring it up on my iPhone I get a "Cannot open Page because too many redirects" error. Does anyone know why this would be?

Thanks!

Recommended Answers

All 5 Replies

If this code is rused on your mobile subdomain as well, it's possible you have entered a redirect loop.

Make sure your index.php file at mobile.sitename.com does not include any redirects.

No, there's no code on the index.php page that's on the mobile domain. I have that php code on the index.php of the regular site domain.

Shame lol, always worth checking for the quick fix.

I'm going to assume your problem is specific to the iPhone because you said the code "usually works", but it may be worth checking with different mobile browsers.

You could try clearing the history/cache - apparently safari will store redirect info. I'm guessing you would have tried this, but I mention it because of the following apple support thread:

http://discussions.apple.com/message.jspa?messageID=10317040

Let us know how you get on and post any information tha might be useful in finding a fix :)

It is working on my iphone now. But it's not working on the Palm Pre or Blackberry. I'm assuming it won't work for the other browsers as well. Not sure why!

Glad it's working now for you, on the iPhone at least. I did just realize something that may be of use to you.

My Android phone browser has a setting that allows me as the user to dictate whether or not to use the mobile version of a site (a check box for "Mobile View"). If you have solved the redirect issue but some phone browsers just show your main site, this may be the cause.

Some phones are spoofing their user agent in order to load the full version of a website instead of the mobile one, for example I like to use facebook mobile, but the full version of BBC iPlayer.

You can use a firefox addon to make sites think the client is a range of different devices. You can use it to see if your code is behaving as expected. See here:

https://addons.mozilla.org/en-US/firefox/addon/59/

Just use google to find the UA strings of your target devices.

Remember to post your solution and mark the thread as solved :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.