1

I have a full site that has been in OS-commerce and mobile site is in core PHP (codeignitor), and full version and a mobile version on sub-domain.

e.g full site: www.example.com and mobile site domain is m.example.com. when user open full site domain in mobile, then website redirect proper mobile domain, But if mobile user want to view full site then user can view fullsite in mobile.

I have used this to complete the redirect http://code.google.com/p/php-mobile-detect/, But it is not redirecting to the full site or to the mobile site using session. I know that I have to use PHP SESSIONS and REQUEST in order to get this to work but I am not sure how to use them in this instance, so could you please suggest how to solve this redirecting issue using session?

Here my code is:

session_start(); 

  include('includes/Mobile_Detect.php');
  $detect = new Mobile_Detect;

 if(isset($_REQUEST['fullsite']) && $_REQUEST['fullsite'] == 'yes')
 {//check if fullsite view request from mobile or website?

    $_SESSION['fullsite']="yes";

    if($detect->isMobile()) {
               $_SESSION['website']="mobile";
    }
    else{
       $_SESSION['website']="computer"; 
    }

    $deviceType = header('Location: https://www.example.com/');
  }
  else
  {
    if($_SESSION['website'] =="mobile"  && $_SESSION['fullsite'] !="yes")
    {
        if($detect->isTablet())
        {
            $deviceType = 'tablet';
        }
        else
        {
            $deviceType = 'phone';
        }

        $deviceType = header('Location: https://m.example.com/');
    }
    elseif($_SESSION['website'] =="computer" && $_SESSION['fullsite'] =="yes")
    {
        $deviceType = 'computer';
        $deviceType = header('Location: https://www.example.com/');
    }
    else{   
        $deviceType = 'computer';
     }

    $scriptVersion = $detect->getScriptVersion();
    session_destroy();
  }
Jay Kareliya
  • 760
  • 7
  • 21

1 Answers1

0

From what I could get from github page you should be able to make it work like this:

index.php

session_start();

if ($_GET['fullscreen'] == 'yes') {
    $_SESSION['fullscreen'] = 1;
} else if ($_GET['fullscreen'] == 'no') {
    $_SESSION['fullscreen'] = 0;
}

if (false == isset($_SESSION['fullscreen']) && ($_SESSION['fullscreen'] == 0)) {
    // If session['fullscreen'] has not been set (maybe first visit
    // or the user does not what in fullscree
    // check the device and do redirect
    require_once 'Mobile_Detect.php';
    $detect = new Mobile_Detect();


    // Any mobile device (phones or tablets).
    if ( $detect->isMobile() ) {

    }
    ...
}

// Other code here

When visiting from mobile, if the user wants the full version, provide an anchor to url with GET parameter fullscreen=yes (http://example.com?fullscreen=yes) If on full site and detect mobile (not included in code above), you could provide a link to mobile version with fullscreen=no

ep0
  • 710
  • 5
  • 13