drupal_detect_baseurl

Versions
5 – 7
drupal_detect_baseurl($file = 'install.php')

Auto detect the base_url with PHP predefined 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

Code

includes/install.inc, line 126

<?php
function drupal_detect_baseurl($file = 'install.php') {
  global $profile;
  $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";
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.