diff --git a/html/main.php b/html/main.php
index df88d5fb7d34bcf83dba49c208589da699252363..9433a3decf31039179aebd3eaccc2990ac0d8b25 100644
--- a/html/main.php
+++ b/html/main.php
@@ -198,7 +198,7 @@ if ($old_plugin_dir != $plugin_dir && $old_plugin_dir != "") {
 }
 
 /* Check for sizelimits */
-eval_sizelimit();
+$ui->getSizeLimitHandler()->update();
 
 /* Check for memory */
 if (function_exists("memory_get_usage")) {
diff --git a/include/class_config.inc b/include/class_config.inc
index bbfbeb90813619f6e7b8b542cc4cc1ed8c5431fc..c28ecded64c571c813d6e1f160ad240411374729 100644
--- a/include/class_config.inc
+++ b/include/class_config.inc
@@ -313,8 +313,9 @@ class config
    */
   function get_ldap_link($sizelimit = FALSE)
   {
-    if ($this->ldap === NULL || !is_resource($this->ldap->cid)) {
+    global $ui;
 
+    if ($this->ldap === NULL || !is_resource($this->ldap->cid)) {
       /* Build new connection */
       $this->ldap = ldap_init ($this->current['SERVER'], $this->current['BASE'],
           $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
@@ -331,16 +332,11 @@ class config
       } else {
         $this->ldap->referrals = $this->current['REFERRAL'];
       }
-
-      if (!session::global_is_set('size_limit')) {
-        session::global_set('size_limit',   $this->current['LDAPSIZELIMIT']);
-        session::global_set('size_ignore',  preg_match('/true/i', $this->current['LDAPSIZEIGNORE']));
-      }
     }
 
     $obj  = new ldapMultiplexer($this->ldap);
     if ($sizelimit) {
-      $obj->set_size_limit(session::global_get('size_limit'));
+      $obj->set_size_limit($ui->getSizeLimitHandler()->getSizeLimit());
     } else {
       $obj->set_size_limit(0);
     }
@@ -386,20 +382,9 @@ class config
       $this->current['ADMINPASSWORD'] = $this->current['REFERRAL'][$this->current['SERVER']]['ADMINPASSWORD'];
     }
 
-    /* We need LDAPSIZELIMIT and LDAPSIZEIGNORE set before we connect to the ldap */
-    if (!isset($this->current['LDAPSIZELIMIT'])) {
-      $this->current['LDAPSIZELIMIT'] = 200;
-    }
-    if (!isset($this->current['LDAPSIZEIGNORE'])) {
-      $this->current['LDAPSIZEIGNORE'] = "TRUE";
-    }
-
     /* Load in-ldap configuration */
     $this->load_inldap_config();
 
-    /* We update LDAPSIZELIMIT as it may have been changed by ldap config */
-    session::global_set('size_limit', $this->current['LDAPSIZELIMIT']);
-
     if (class_available('systemManagement')) {
       /* Load server informations */
       $this->load_servers();
diff --git a/include/class_filterLDAP.inc b/include/class_filterLDAP.inc
index 7053e6f8f7165853a08f5fe6feb10751d09c678b..a887dd0a643bba9235d0451dccdb26645606f66b 100644
--- a/include/class_filterLDAP.inc
+++ b/include/class_filterLDAP.inc
@@ -141,7 +141,7 @@ class filterLDAP
 
       // Check for size limit exceeded messages for GUI feedback
       if (preg_match("/size limit/i", $ldap->get_error())) {
-        session::set('limit_exceeded', TRUE);
+        $ui->getSizeLimitHandler()->setLimitExceeded();
         $limit_exceeded = TRUE;
       }
 
diff --git a/include/class_ldapSizeLimit.inc b/include/class_ldapSizeLimit.inc
new file mode 100644
index 0000000000000000000000000000000000000000..01fe97de4b229babc8701017fbd11d5e98b57a89
--- /dev/null
+++ b/include/class_ldapSizeLimit.inc
@@ -0,0 +1,140 @@
+<?php
+/*
+  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
+  Copyright (C) 2017-2018  FusionDirectory
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+*/
+
+/*!
+ * \file class_ldapSizeLimit.inc
+ * Source code for the class ldapSizeLimit
+ */
+
+/*!
+ * \brief Class ldapSizeLimit
+ * This class contains all informations and functions to handle the LDAP size limit dialogs, configuration and bypass
+ */
+
+class ldapSizeLimit
+{
+  /*! \brief Current size limit */
+  protected $sizeLimit;
+
+  /*! \brief Ignore dialogs */
+  protected $ignore;
+
+  /*! \brief Limit was exceeded */
+  protected $limitExceeded;
+
+  function __construct()
+  {
+    global $config;
+
+    $this->sizeLimit  = $config->get_cfg_value('LDAPSIZELIMIT', 200);
+    $this->ignore     = preg_match('/true/i', $config->get_cfg_value('LDAPSIZEIGNORE'));
+  }
+
+  function getSizeLimit()
+  {
+    return $this->sizeLimit;
+  }
+
+  function setSizeLimit($limit)
+  {
+    $this->sizeLimit = $limit;
+  }
+
+  function setLimitExceeded($exceeded = TRUE)
+  {
+    $this->limitExceeded = $exceeded;
+  }
+
+  /*!
+   * \brief Handle sizelimit dialog related posts
+   */
+  function update()
+  {
+    if (isset($_POST['set_size_action']) && isset($_POST['action'])) {
+      switch ($_POST['action']) {
+        case 'newlimit':
+          if (isset($_POST['new_limit']) && tests::is_id($_POST['new_limit'])) {
+            $this->sizeLimit  = intval($_POST['new_limit']);
+            $this->ignore     = FALSE;
+          }
+          break;
+        case 'ignore':
+          $this->sizeLimit  = 0;
+          $this->ignore     = TRUE;
+          break;
+        case 'limited':
+          $this->ignore     = TRUE;
+          break;
+        default:
+          break;
+      }
+    }
+
+    /* Allow fallback to dialog */
+    if (isset($_POST['edit_sizelimit'])) {
+      $this->ignore = FALSE;
+    }
+  }
+
+  /*!
+   * \brief Show sizelimit configuration dialog
+   *
+   * Show sizelimit configuration dialog when number
+   * of entries exceeded the sizelimit
+   */
+  function check()
+  {
+    global $config;
+
+    /* Ignore dialog? */
+    if ($this->ignore) {
+      return '';
+    }
+
+    /* Eventually show dialog */
+    if ($this->limitExceeded) {
+      $smarty = get_smarty();
+      $smarty->assign('warning', sprintf(_('The size limit of %d entries is exceed!'), $this->sizeLimit));
+      $smarty->assign('limit_message', sprintf(_('Set the new size limit to %s and show me this message if the limit still exceeds'), '<input type="text" name="new_limit" maxlength="10" size="5" value="'.($this->sizeLimit + 100).'"/>'));
+      return $smarty->fetch(get_template_path('sizelimit.tpl'));
+    }
+
+    return '';
+  }
+
+  /*!
+   * \brief Print a sizelimit warning
+   *
+   * Print a sizelimit warning when number
+   * of entries exceeded the sizelimit
+   */
+  function renderWarning()
+  {
+    if (($this->sizeLimit >= 10000000) || $this->limitExceeded) {
+      $config = '<input type="submit" name="edit_sizelimit" value="'._('Configure').'"/>';
+    } else {
+      $config = '';
+    }
+    if ($this->limitExceeded) {
+      return '('._('incomplete').") $config";
+    }
+    return '';
+  }
+}
diff --git a/include/class_listing.inc b/include/class_listing.inc
index 6d16ff806bd7a36fb809ca7329360d23000d4e1f..51c99396d8f32ce4f4be75fe9a30140501a47d89 100644
--- a/include/class_listing.inc
+++ b/include/class_listing.inc
@@ -338,8 +338,10 @@ class listing
    */
   function render()
   {
+    global $ui;
+
     // Check for exeeded sizelimit
-    if (($message = check_sizelimit()) != '') {
+    if (($message = $ui->sizeLimitHandler()->check()) != '') {
       return $message;
     }
 
@@ -482,7 +484,7 @@ class listing
     $smarty = get_smarty();
     $smarty->assign("usePrototype", "true");
     $smarty->assign("FILTER", $this->filter->render());
-    $smarty->assign("SIZELIMIT", print_sizelimit_warning());
+    $smarty->assign("SIZELIMIT", $ui->sizeLimitHandler()->renderWarning());
     $smarty->assign("LIST", $result);
     $smarty->assign("MULTISELECT", $this->multiSelect);
 
@@ -1203,7 +1205,7 @@ class listing
    */
   function getAction()
   {
-    global $config;
+    global $config, $ui;
 
     // Do not do anything if this is not our PID, or there's even no PID available...
     if (!isset($_REQUEST['dn']) && (!isset($_REQUEST['PID']) || $_REQUEST['PID'] != $this->pid)) {
@@ -1249,11 +1251,11 @@ class listing
           $this->filter->setCurrentScope('one');
         }
         /* Bypass size limit just to be sure */
-        $oldsizelimit = session::global_get('size_limit');
-        session::global_set('size_limit', 0);
+        $oldsizelimit = $ui->getSizeLimitHandler()->getSizeLimit();
+        $ui->getSizeLimitHandler()->setSizeLimit(0);
         $this->update();
         $this->render();
-        session::global_set('size_limit', $oldsizelimit);
+        $ui->getSizeLimitHandler()->setSizeLimit($oldsizelimit);
         $this->filter->elementValues['NAME'] = '';
 
         $result['action']     = $action;
diff --git a/include/class_userinfo.inc b/include/class_userinfo.inc
index 149a7cc0fce805980bf5472dabb7c6b4db453b80..da2a32c0df61a017d1113c378defe5a247a627a4 100644
--- a/include/class_userinfo.inc
+++ b/include/class_userinfo.inc
@@ -49,6 +49,9 @@ class userinfo
   var $ACLperPath             = array();
   var $ACLperPath_usesFilter  = array();
 
+  /*! \brief LDAP size limit handler */
+  protected $sizeLimitHandler;
+
   /* get acl's an put them into the userinfo object
      attr subtreeACL (userdn:components, userdn:component1#sub1#sub2,component2,...) */
   function __construct($userdn)
@@ -61,6 +64,8 @@ class userinfo
 
     /* Initialize ACL_CACHE */
     $this->reset_acl_cache();
+
+    $this->sizeLimitHandler = new ldapSizeLimit();
   }
 
   /*! \brief Loads user information from LDAP */
@@ -1044,5 +1049,10 @@ class userinfo
     }
     return FALSE;
   }
+
+  function getSizeLimitHandler()
+  {
+    return $this->sizeLimitHandler;
+  }
 }
 ?>
diff --git a/include/functions.inc b/include/functions.inc
index 90c37abe14a70ecfaa16f9b5998937cbec0af2e0..70ec569ee8b9b0f84cecc6f949860128939c28c8 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -793,83 +793,6 @@ function get_locks($objects, $allow_readonly = FALSE)
   return $locks;
 }
 
-/*!
- * \brief Show sizelimit configuration dialog
- *
- * Show sizelimit configuration dialog when number
- * of entries exceeded the sizelimit
- */
-function check_sizelimit()
-{
-  /* Ignore dialog? */
-  if (session::global_is_set('size_ignore') && session::global_get('size_ignore')) {
-    return '';
-  }
-
-  /* Eventually show dialog */
-  if (session::is_set('limit_exceeded') && session::get('limit_exceeded')) {
-    $smarty = get_smarty();
-    $smarty->assign('warning', sprintf(_('The size limit of %d entries is exceed!'),
-          session::global_get('size_limit')));
-    $smarty->assign('limit_message', sprintf(_('Set the new size limit to %s and show me this message if the limit still exceeds'), '<input type="text" name="new_limit" maxlength="10" size="5" value="'.(session::global_get('size_limit') + 100).'"/>'));
-    return $smarty->fetch(get_template_path('sizelimit.tpl'));
-  }
-
-  return '';
-}
-
-/*!
- * \brief Print a sizelimit warning
- *
- * Print a sizelimit warning when number
- * of entries exceeded the sizelimit
- */
-function print_sizelimit_warning()
-{
-  if (session::global_is_set('size_limit') && session::global_get('size_limit') >= 10000000 ||
-      (session::is_set('limit_exceeded') && session::get('limit_exceeded'))) {
-    $config = '<input type="submit" name="edit_sizelimit" value="'._('Configure').'"/>';
-  } else {
-    $config = '';
-  }
-  if (session::is_set('limit_exceeded') && session::get('limit_exceeded')) {
-    return '('._('incomplete').") $config";
-  }
-  return '';
-}
-
-
-/*!
- * \brief Handle sizelimit dialog related posts
- */
-function eval_sizelimit()
-{
-  if (isset($_POST['set_size_action']) && isset($_POST['action'])) {
-    switch ($_POST['action']) {
-      case 'newlimit':
-        if (isset($_POST['new_limit']) && tests::is_id($_POST['new_limit'])) {
-          session::global_set('size_limit', validate($_POST['new_limit']));
-          session::set('size_ignore', FALSE);
-        }
-        break;
-      case 'ignore':
-        session::global_set('size_limit', 0);
-        session::global_set('size_ignore', TRUE);
-        break;
-      case 'limited':
-        session::global_set('size_ignore', TRUE);
-        break;
-      default:
-        break;
-    }
-  }
-
-  /* Allow fallback to dialog */
-  if (isset($_POST['edit_sizelimit'])) {
-    session::global_set('size_ignore', FALSE);
-  }
-}
-
 /*!
  * \brief Return the current userinfo object
  *