Community Documentation

$base_url

  1. drupal
    1. 6 globals.php
    2. 7 globals.php
    3. 8 globals.php

The base URL of the Drupal installation.

See also

drupal_settings_initialize()

File

developer/globals.php, line 22
These are the global variables that Drupal uses.

Code

<?php
global $base_url
?>

Comments

[From the D6 API

[From the D6 API comments:]

Base URL will begin with https:// if the current page is being accessed through the HTTPS protocol. This depends on the availability of $_SERVER['HTTPS'] which may not be available if a reverse proxy or load balancer is in use.

Also, the $base_url does not include the trailing slash, like so:

http://www.example.com

If you're using the $base_url to construct a link, make sure you add the trailing slash, like so:

<?php
  $link
= $base_url . '/node/add';
?>

Includes path

If Drupal is in a subdirectory, it includes the path to the subdirectory when follows

global $base_url;

access through $GLOBALS array

<?php
$link
= $GLOBALS['base_url'] . '/node/' . $node->nid;
?>

as with any super global variable you can access through $GLOBALS array.
here is a link to a node id.

Consider using l()

As a side note, creating a link to a node is better done with l(). This example will not work on a site with clean URLs turned off.

Login or register to post comments