You are here

function redirect_can_redirect in Redirect 7

Same name and namespace in other branches
  1. 7.2 redirect.module \redirect_can_redirect()

Check the ability to perform redirects with the current request context.

This function checks the following conditions:

  • If the PHP entry point is the root index.php file.
  • If PHP is not running as CLI.
  • If the site is not offline or in install/update mode.
  • If the curerent page is not an admin page (check can be disabled).
  • If the current request does not have any POST data since a redirect may interrupt form submission.

Return value

TRUE if redirections can be performed, or FALSE otherwise.

1 call to redirect_can_redirect()
redirect_init in ./redirect.module
Implements hook_init().

File

./redirect.module, line 1307

Code

function redirect_can_redirect() {
  $can_redirect =& drupal_static(__FUNCTION__);
  if (!isset($can_redirect)) {
    $path = current_path();
    $can_redirect = TRUE;
    if (!preg_match('/index\\.php$/', $_SERVER['SCRIPT_NAME'])) {

      // Do not redirect if the root script is not /index.php.
      $can_redirect = FALSE;
    }
    elseif (!empty($_POST)) {

      // Do not redirect if this is a post request with data.
      $can_redirect = FALSE;
    }
    elseif (drupal_is_cli()) {

      // If this is a command line request (Drush, etc), skip processing.
      $can_redirect = FALSE;
    }
    elseif ((variable_get('maintenance_mode', 0) || defined('MAINTENANCE_MODE')) && !user_access('access site in maintenance mode')) {

      // Do not redirect in offline or maintenance mode.
      $can_redirect = FALSE;
    }
    elseif (!variable_get('redirect_global_admin_paths', 0) && path_is_admin($path)) {

      // Do not redirect on admin paths.
      $can_redirect = FALSE;
    }
  }
  return $can_redirect;
}