function drupal_detect_baseurl

drupal_detect_baseurl($file = 'install.php')

Detects the base URL using the PHP $_SERVER variables.

Parameters

$file: The name of the file calling this function so we can strip it out of the URI when generating the base_url.

Return value

The auto-detected $base_url that should be configured in settings.php

File

includes/install.inc, line 221
API functions for installing modules and themes.

Code

function drupal_detect_baseurl($file = 'install.php') {
  $proto = $_SERVER['HTTPS'] ? 'https://' : 'http://';
  $host = $_SERVER['SERVER_NAME'];
  $port = ($_SERVER['SERVER_PORT'] == 80 ? '' : ':' . $_SERVER['SERVER_PORT']);
  $uri = preg_replace("/\?.*/", '', $_SERVER['REQUEST_URI']);
  $dir = str_replace("/$file", '', $uri);

  return "$proto$host$port$dir";
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/includes!install.inc/function/drupal_detect_baseurl/7.x