[imp] PHP question: which code is better?

Sean D. mojospam at thegeekclub.net
Sat May 15 09:02:59 PDT 2004


sorry in advance a bit off-topic but...

i'm defining my own $GLOBAL in registry.php for use in other parts of the code 
to help set a variable for virtual domains. (yes we use the vhook function too) 
but i was wondering what you guys thought would be the best code to use...?
(FYI, i have PHP 4.3.4 on Apache 2.0 on Redhat9)

this one(registry.php):

$patterns[0] = "/^webmail\./";
$patterns[1] = "/^www\./";
$patterns[2] = "/^mail\./";
$ServerName = preg_replace($patterns, '', $_SERVER['SERVER_NAME']);
$DomainName = ($ServerName != '') ? $ServerName : 'mydomain.com';

or this one:

$headers = getallheaders();
$patterns[0] = "/^webmail\./";
$patterns[1] = "/^www\./";
$patterns[2] = "/^mail\./";
$ServerName = preg_replace($patterns, '', $headers['Host']);
$DomainName = ($ServerName != '') ? $ServerName : 'mydomain.com';

then of course i set that global like this:

$this->applications['horde'] = array(
  'domain_name' => $DomainName
);

and call it up from other files like this:

$testvar = $GLOBALS['registry']->getParam('domain_name');

its true i could have performed that operation on the server_name variable but i 
prefer not to mess with the vars already set too much because i'm such a 
beginner at PHP...

i think i already know what most will say.. i assume the first option is the 
best. but there may be an even better/faster method i havent considered?
i use this variable in a few places... mostly for cosmetic stuff like making
passwd show "Changing password on mydomain.com" instead of "poppassd".. stuff 
like that.

thanks,
Sean D.


More information about the imp mailing list