r2b2
r2b2

Reputation: 1275

Drupal where to set global variables accessible to all pages on the site?

Im working on a Drupal installation where the setup in my local testing server is different from online server.

On my local server drupal is installed in /var/www/my_drupal and the base_path is set to /mydrupal but on the online server its installed on the root of the site, usually /public_html/

So my problem is I wanted to set a base_path and base_url variable depending on the server i am on. Where do i place my codes so that it's accessible site-wide.?

Thanks!

Upvotes: 0

Views: 2328

Answers (2)

wiifm
wiifm

Reputation: 3798

Luckily Drupal already has taken care of this for you

See the api site for a full listing

Of particular interest to you should be:

$base_path developer/globals.php The base path of the drupal installation. At least will default to /.
$base_url developer/globals.php The base URL of the drupal installation.

Upvotes: 1

geoffs3310
geoffs3310

Reputation: 14018

I would set it in your settings file in sites/default/settings.php just use an if statement to detect whether it is the local or live site ur on and then set the variables accordingly.

if ($_SERVER['SERVER_NAME'] == 'localhost') { // the script is running on the local } else { // it is on remote }

Upvotes: 0

Related Questions