User login

Get the complete base URL for a Drupal site

Certain things in the world of Drupal, such as the the shockwave function, swf(), expect a full, absolute URL path and not the relative path (such as just a slash).

<?php
global $base_url;
print
$base_url;
?>

You will probably want to do something more interesting than print. It does not include the trailing slash (/).

Resolution

Searched words: 
drupal absolute path drupal full path base path

Comments

How to set base_path

where can i set this path, I have uplaoded my site at root bath from a deep level folder now my i print this variable i.e $base_path, it will just return '/', it should return 'www.abc.com'

sO what can i do

L2R

Eshban, you need to look closer. $base_url and $base_path are two different things. $base_path will return your subfolder, or at least "/", if you installed it in root.

To get the full url to your Drupal, you can use:

<?php
  print $base_url . $base_path;
?>

If you are using views, then

If you are using views, then it is better to use $GLOBALS to access both values.

Otherwise $base_url came blank to me.

<?php
print $GLOBALS['base_url'] . $GLOBALS['base_path'];
?>

You can further concatenate

drupal_lookup_path('alias',"node/".$data->nid);

to get complete path to any node.

as

<?php
print $GLOBALS['base_url'] . $GLOBALS['base_path'] . drupal_lookup_path('alias',"node/".$data->nid);
?>

Thanks

L2R is right about basepath -

L2R is right about basepath - it is required if the site is in a directory under the web root.

It is worth noting that base_path can be accessed via function (for some reason) - so the full code becomes:

global $base_url;
$site_path = $base_url . base_path();

Thanks for sharing

Thanks for sharing

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Syntax highlight code surrounded by the {syntaxhighlighter SPEC}...{/syntaxhighlighter} tags, where SPEC is a Syntaxhighlighter options string or "class="OPTIONS" title="the title".
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.