Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-06-2010, 08:04 PM   PM User | #1
shagey36
New to the CF scene

 
Join Date: Sep 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shagey36 is an unknown quantity at this point
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?
shagey36 is offline   Reply With Quote
Old 09-07-2010, 09:31 PM   PM User | #2
kbluhm
Senior Coder

 
kbluhm's Avatar
 
Join Date: Apr 2007
Location: Philadelphia, PA, USA
Posts: 1,502
Thanks: 2
Thanked 258 Times in 254 Posts
kbluhm will become famous soon enough
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 ) )
{
    include 
$file;

__________________
ZCE

Last edited by kbluhm; 09-08-2010 at 02:30 AM..
kbluhm is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:14 PM.


Advertisement
Log in to turn off these ads.