--- ip_login/ip_login.module.orig	2014-06-10 13:58:03.428540593 +0900
+++ ip_login/ip_login.module	2014-06-10 15:25:38.772611590 +0900
@@ -21,6 +21,7 @@ define('IP_CHECKED', 'ip_login_checked')
 define('IP_UID_MATCH', 'ip_login_uid'); // TRUE when a user account matches the request IP
 define('LOGIN_AS_DIFFERENT_USER', 'ip_login_as_different_user'); // TRUE when user wants alternate account
 define('CACHE_DISABLED', 0);  // D7 TODO: this is removed from bootstrap.inc, and now in?? --> avoid double definition
+define('DESTINATION', 'ip_login_destination');  // if user/login called with destination
 
 /**
  * Implementation of hook_boot().
@@ -157,7 +158,11 @@ function ip_login_attempt_login() {
   if ($matched_uid > 0) {
     ip_login_login($matched_uid);
   }
-  drupal_goto(variable_get('ip_login_destination', 'user'));
+  if (isset($_SESSION[DESTINATION]) && variable_get('ip_login_destination', '') == "" ) {
+    drupal_goto($_SESSION[DESTINATION]);
+  } else {
+    drupal_goto(variable_get('ip_login_destination', 'user'));
+  }
 }
 
 /**
@@ -186,6 +191,11 @@ function ip_login_form_alter(&$form, &$f
     case 'user_login':
       $matched_uid = ip_login_check(ip_address());
       if ($matched_uid > 0) {
+        if ( isset($_GET['destination']) ) {
+          $_SESSION[DESTINATION] = $_GET['destination'];
+        } else {
+          unset($_SESSION[DESTINATION]);
+        }
         $link_text = t(variable_get('ip_login_link_login_page', 'Log in automatically'));
         if (drupal_strlen($link_text)) { // hide if no link text
           $link_help = t(variable_get('ip_login_link_login_page_help', "Your computer's IP address has been matched and validated."));
