You are here

function login_destination_redirect_to_path_and_query in Login Destination 6.2

1 call to login_destination_redirect_to_path_and_query()
login_destination_user in ./login_destination.module
Implementation of hook_user().

File

./login_destination.module, line 191
Control where users are directed to, once they login

Code

function login_destination_redirect_to_path_and_query($path, $query) {

  // prepare query: rawurlencode, handle array/string
  if (!empty($query)) {

    // from array to An urlencoded string which can be appended to/as the URL query string.
    // uses rawurlencode
    if (is_array($query)) {
      $query_str_rawurlencoded = drupal_query_string_encode($query);
      $query_for_goto = $query;

      // pass array as is to drupal_goto
    }
    else {
      $query_str_rawurlencoded = rawurlencode($query);
      $query_for_goto = $query_str_rawurlencoded;

      // drupal_goto can accpet urlencoded query string too
    }
  }
  $query_for_destination = !empty($query_str_rawurlencoded) ? rawurlencode('?') . $query_str_rawurlencoded : '';

  // prepare $path - can be absolute, relative
  $path = ltrim($path, "/");

  // won't harm absolute ones, meant for internal=relative ones
  $path_for_destination = rawurlencode($path);
  $path_for_goto = $path;

  // goto does not need url encoded $path
  // update the destination parameter
  $_REQUEST['destination'] = $path_for_destination . $query_for_destination;

  // 1. Redirect ( using absolute url in $path won't actually work, so if we want it to work we need drupal_goto )
  // 2. potentially breaks content_profile_registration's function: see: 'not working with content profile module ? : https://www.drupal.org/node/761254'
  // ... but only when logging the user in right after register, without email confirmation - see settings page MORE INFO
  if (variable_get('ld_use_drupal_goto', 0) == 1) {
    drupal_goto($path_for_goto, $query_for_goto, NULL, 301);
  }
}