Home ›
Get the complete base URL for a Drupal siteGet the complete base URL for a Drupal site
Submitted by Benjamin Melançon on April 14, 2009 - 7:32pm
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