Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
09-06-2010, 09:04 PM #1
- Join Date
- Sep 2010
- Thanked 0 Times in 0 Posts
defining constants in the configuration?
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.
I have /var/www/blah.com/constants.php
I would like the correct constants.php file to get included when I go to the domain.
09-07-2010, 10:31 PM #2
- 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!
// 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.