diff --git a/htdocs/core/ajax/selectsearchbox.php b/htdocs/core/ajax/selectsearchbox.php
index 2e837fcbaae9a4b2c92e42a93b79f3e828cbbddd..2d92bc8f938bb0dc96a228cb8c43d8a69a045a07 100644
--- a/htdocs/core/ajax/selectsearchbox.php
+++ b/htdocs/core/ajax/selectsearchbox.php
@@ -31,8 +31,17 @@ if (! isset($usedbyinclude) || empty($usedbyinclude))
     if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
     if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
     if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
+    if (! defined('NOREDIRECTBYMAINTOLOGIN')) define('NOREDIRECTBYMAINTOLOGIN','1');
 
     $res=@include '../../main.inc.php';
+    if ($res == 'ERROR_NOT_LOGGED')
+    {
+    	$langs->load("other");
+    	$arrayresult['jumptologin']=array('img'=>'object_generic', 'label'=>$langs->trans("JumpToLogin"), 'text'=>'<span class="fa fa-sign-in"></span> '.$langs->trans("JumpToLogin"), 'url'=>DOL_URL_ROOT.'/index.php');
+    	print json_encode($arrayresult);
+    	if (is_object($db)) $db->close();
+    	exit;
+    }
 }
 
 include_once DOL_DOCUMENT_ROOT.'/core/lib/json.lib.php';
diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang
index e519f7af405922279afec280772f4256476dbfa9..bd52f5dcaa23390df897183c1fdfe8cd441a3894 100644
--- a/htdocs/langs/en_US/other.lang
+++ b/htdocs/langs/en_US/other.lang
@@ -18,6 +18,7 @@ NextMonthOfInvoice=Following month (number 1-12) of invoice date
 TextNextMonthOfInvoice=Following month (text) of invoice date
 ZipFileGeneratedInto=Zip file generated into <b>%s</b>.
 DocFileGeneratedInto=Doc file generated into <b>%s</b>.
+JumpToLogin=Disconnected. Go to login page...
 
 YearOfInvoice=Year of invoice date
 PreviousYearOfInvoice=Previous year of invoice date
diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php
index 1edc67d582f44033ba54fd179842a8ec0f648238..090a35d6c8337d788f58840450ef14076b593ef6 100644
--- a/htdocs/main.inc.php
+++ b/htdocs/main.inc.php
@@ -457,9 +457,7 @@ if (! defined('NOLOGIN'))
         $passwordtotest	= GETPOST('password','none',2);
         $entitytotest	= (GETPOST('entity','int') ? GETPOST('entity','int') : (!empty($conf->entity) ? $conf->entity : 1));
 
-        // Validation of login/pass/entity
-        // If ok, the variable login will be returned
-        // If error, we will put error message in session under the name dol_loginmesg
+        // Define if we received data to test the login.
         $goontestloop=false;
         if (isset($_SERVER["REMOTE_USER"]) && in_array('http',$authmode)) $goontestloop=true;
         if ($dolibarr_main_authentication == 'forceuser' && ! empty($dolibarr_auto_user)) $goontestloop=true;
@@ -473,6 +471,9 @@ if (! defined('NOLOGIN'))
         	$langs->setDefaultLang($langcode);
         }
 
+        // Validation of login/pass/entity
+        // If ok, the variable login will be returned
+        // If error, we will put error message in session under the name dol_loginmesg
         if ($test && $goontestloop)
         {
         	$login = checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmode);
@@ -531,9 +532,10 @@ if (! defined('NOLOGIN'))
         // End test login / passwords
         if (! $login || (in_array('ldap',$authmode) && empty($passwordtotest)))	// With LDAP we refused empty password because some LDAP are "opened" for anonymous access so connexion is a success.
         {
-            // We show login page
+            // No data to test login, so we show the login page
 			dol_syslog("--- Access to ".$_SERVER["PHP_SELF"]." showing the login form and exit");
-        	dol_loginfunction($langs,$conf,(! empty($mysoc)?$mysoc:''));
+			if (defined('NOREDIRECTBYMAINTOLOGIN')) return 'ERROR_NOT_LOGGED';
+        	else dol_loginfunction($langs,$conf,(! empty($mysoc)?$mysoc:''));
             exit;
         }