PHP mobile redirect Endless loop

Disable the plugin at all and in your function.php add

add_action('init', 'my_mobile_redirect');

function get_first_url_subdir() {
  return str_replace( str_replace( array('http://', 'https://'), '', get_site_url() ), '', $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']);
} 

function redirect_mobile_with_cookie() {
  $cookiename="redirect_mobile_is_a_mobile_device";
  if ( isset($_COOKIE[$cookiename]) && ($_COOKIE[$cookiename] == 'yes') && strpos(get_first_url_subdir(), '/mobile') !== 0)
    return true;
  return false;
} 

function my_mobile_redirect(){
  if ( redirect_mobile_with_cookie() ) {
     wp_redirect( get_site_url() . '/mobile/');
     exit();
  } elseif  ( strpos(get_first_url_subdir(), '/mobile') !== 0 && wp_is_mobile() ) {
    $cookiename="redirect_mobile_is_a_mobile_device";
    setcookie($cookiename, 'yes');
    wp_redirect( get_site_url() . '/mobile/');
    exit();
  }
}

Previous functions works with WordPress wp_is_mobile function that do not differentiate between tablets and phones.

If you need to differentiate between tablets and phones you can use the script Mobile Detect. Download it, put in a folder. For semplicity here I assume Mobile_Detect.php resides in theme root.

The following function works in combination with the three above.

function my_adv_mobile_redirect() {
   if ( redirect_mobile_with_cookie() ) {
     wp_redirect( get_site_url() . '/mobile/');
     exit();
  } else {
    @include_once( trailingslashit(TEMPLATEPATH) . 'Mobile_Detect.php' );
    if ( ! class_exists('Mobile_Detect') ) return my_mobile_redirect();
    $detect = new Mobile_Detect;
    // redirects only phones
    if  (strpos(get_first_url_subdir(), '/mobile') !== 0 && ($detect->isMobile() && ! $detect->isTablet())) {
      $cookiename="redirect_mobile_is_a_mobile_device";
      setcookie($cookiename, 'yes');
      wp_redirect( get_site_url() . '/mobile/');
      exit();
    }
  }
}

If you want to use this advanced function just replace the init action in the previous code with: add_action('init', 'my_adv_mobile_redirect')