Classic View / Mobile View Switch?

I am creating a version of my website with the jQuery Mobile platform. Although it would be pretty easy to do javascript redirects to get mobile device users to our mobile site, I don’t want people to not be able to view the classic website.

What is the best way to accomplish this?

Our regular website is located at:

us.companyname.com/

Our mobile site will:

us.companyname.com/mobile

There are some restrictions, since we do not own a domain name, our British colleagues, so getting something at the companyname.com level requires some patience. Basically, if someone from North America comes to companyname.com, they are automatically redirected to us.companyname.com.

I have full access to our site (written primarily in PHP and the Expression engine, before I was here), and I am free to do everything until I ruined anything.

+3
source share
2 answers

Firstly, I wouldn’t do such things with Javascript / Query, because if the user hadn’t activated js? It is better to do this on the server side.

Something like that:

$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
}
+5
source

Something like this work:

, -, window.location if, , noredirect true. noredirect, .

0

Source: https://habr.com/ru/post/1790465/


All Articles