Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Thanked 0 Times in 0 Posts

    defining constants in the configuration?

    Hello everybody,

    I apologize if this is more of an apache question than it is a php question but I figured I'd give this a shot.

    So I have an apache server running multiple domains and I would like to define constants for each domain without having to explicitly include some sort of constants file at the beginning of every single file. Is there a good place to define constants so they can be accessed anywhere in a given domain?

    I stumbled across 'auto_prepend_file' and that seems like it'll do the trick but I won't want to prepend the same file across all domains.

    For example:
    I have /var/www/blah.com/constants.php
    and /var/www/foo.com/constants.php

    I would like the correct constants.php file to get included when I go to the domain.

    Any ideas?

  2. #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Philadelphia, PA, USA
    Thanked 258 Times in 254 Posts
    Maybe try naming the constants after the domain? Then if it exists, include it!
    PHP Code:
    // Grab hostname
    $host strtolower$_SERVER['HTTP_HOST'] );

    // Remove `www.` prefix if necessary
    $host preg_replace'/^www\./'''$host );

    // Name the file to be included
    // - www.google.com -> `../const/google.com.php`
    $file '../const/' $host '.php';

    // If the file exists, include it
    if ( is_file$file ) )

    Last edited by kbluhm; 09-08-2010 at 03:30 AM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts