I'm building a version of my company's website with the jQuery Mobile framework. While it'd be fairly easy to do a javascript redirect to get users of mobile devices to our mobile site, I don't want to stop people from being able to view the classic website either.
What's the best way to accomplish this?
Our normal website is at:
us.companyname.com/
Our mobile website will be at:
us.companyname.com/mobile
There are some limitations, as we don't hold the domain name, our UK counterparts do, so getting anything done at the companyname.com level takes some patience. Basically, if anyone from North America comes to companyname.com, they'll get automatically redirected to us.companyname.com.
I do have full access to our website (written primarily in PHP & Expression engine, before I was here), and I'm free to do whatever as long as I don't mess anything up.
First, such things i would not do this with Javascript/Query, cause what is if the user has not activate js? It is better to do this server-side.
Something like this:
$mobile = array("IPHONE", "IPAD");
$flagMobileVersion = false;
if($_SESSION['version']!="mobile"){ //happens only at first visit
for($i=0;$i<=count($mobile)-1;$i++){
if(!strrpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $mobile[$i]))
{
$flagMobileVersion = true;
break;
}
}
if($flagMobileVersion) {
$_SESSION['version'] = "mobile";
Header("www.mydomain.net/mobile"); //on first Visit
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With