Better option than $_SERVER["HTTP_HOST"]
Better option than $_SERVER["HTTP_HOST"]
am 05.01.2008 12:04:39 von Jason Carlton
I have several domains parked over my primary domain, and based on
which domain is typed in the content changes slightly for each page
(title bar, keywords, little things like that). But, I'm having a few
minor issues.
Every page calls a variables.php (where all of the variables are set
at once), which goes like:
// www.parkdomain1.com
if (strpos($_SERVER['HTTP_HOST'], "parkdomain1")) {
// set variables
}
// www.parkdomain2.com
else if (strpos($_SERVER['HTTP_HOST'], "parkdomain2")) {
// set variables
}
// www.actualdomain.com
else {
// set variables
}
My question is, is this the best way to find which domain has been
entered? Also, considering that I'm always battling speed issues on my
site, is there a faster option than $_SERVER['HTTP_HOST']?
TIA,
Jason
Re: Better option than $_SERVER["HTTP_HOST"]
am 05.01.2008 14:04:32 von flowover
On Jan 5, 3:04 am, Jason Carlton wrote:
> I have several domains parked over my primary domain, and based on
> which domain is typed in the content changes slightly for each page
> (title bar, keywords, little things like that). But, I'm having a few
> minor issues.
>
> Every page calls a variables.php (where all of the variables are set
> at once), which goes like:
>
> //www.parkdomain1.com
> if (strpos($_SERVER['HTTP_HOST'], "parkdomain1")) {
> // set variables
>
> }
>
> //www.parkdomain2.com
> else if (strpos($_SERVER['HTTP_HOST'], "parkdomain2")) {
> // set variables
>
> }
>
> //www.actualdomain.com
> else {
> // set variables
>
> }
>
> My question is, is this the best way to find which domain has been
> entered? Also, considering that I'm always battling speed issues on my
> site, is there a faster option than $_SERVER['HTTP_HOST']?
>
> TIA,
>
> Jason
You could always try mod_rewrite if you have Apache. It's fairly
robust. http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
Re: Better option than $_SERVER["HTTP_HOST"]
am 05.01.2008 14:46:22 von luiheidsgoeroe
On Sat, 05 Jan 2008 12:04:39 +0100, Jason Carlton
wrote:
> My question is, is this the best way to find which domain has been
> entered?
Yes, at least in Apache with PHP as a module it is.
> Also, considering that I'm always battling speed issues on my
> site, is there a faster option than $_SERVER['HTTP_HOST']?
$_SERVER['HTTP_HOST'] is an automatically filled string allready available
to you, anything faster is almost impossible. When trying to optimise, be
sure to check where the bottlenecks are, don't guess. A variety of tools
is available to you, I prefer XDebug.
About the (pseudo?) code, I'd say you're better of using a switch
statement then an if..else if...else if.. construct.
--
Rik Wasmus
Re: Better option than $_SERVER["HTTP_HOST"]
am 06.01.2008 03:09:48 von flowover
On Jan 5, 5:46 am, "Rik Wasmus" wrote:
> On Sat, 05 Jan 2008 12:04:39 +0100, Jason Carlton
> wrote:
>
> > My question is, is this the best way to find which domain has been
> > entered?
>
> Yes, at least in Apache with PHP as a module it is.
>
> > Also, considering that I'm always battling speed issues on my
> > site, is there a faster option than $_SERVER['HTTP_HOST']?
>
> $_SERVER['HTTP_HOST'] is an automatically filled string allready available
> to you, anything faster is almost impossible. When trying to optimise, be
> sure to check where the bottlenecks are, don't guess. A variety of tools
> is available to you, I prefer XDebug.
>
> About the (pseudo?) code, I'd say you're better of using a switch
> statement then an if..else if...else if.. construct.
> --
> Rik Wasmus
mod_rewrite is faster as it happens inline with the http headers on
the fly. It's just more complex.
Re: Better option than $_SERVER["HTTP_HOST"]
am 06.01.2008 03:23:00 von luiheidsgoeroe
On Sun, 06 Jan 2008 03:09:48 +0100, flowover wrote:
> On Jan 5, 5:46 am, "Rik Wasmus" wrote:
>> On Sat, 05 Jan 2008 12:04:39 +0100, Jason Carlton
>> wrote:
>>
>> > My question is, is this the best way to find which domain has been
>> > entered?
>>
>> Yes, at least in Apache with PHP as a module it is.
>>
>> > Also, considering that I'm always battling speed issues on my
>> > site, is there a faster option than $_SERVER['HTTP_HOST']?
>>
>> $_SERVER['HTTP_HOST'] is an automatically filled string allready
>> available
>> to you, anything faster is almost impossible. When trying to optimise,
>> be
>> sure to check where the bottlenecks are, don't guess. A variety of tools
>> is available to you, I prefer XDebug.
>>
>> About the (pseudo?) code, I'd say you're better of using a switch
>> statement then an if..else if...else if.. construct.
>
> mod_rewrite is faster as it happens inline with the http headers on
> the fly. It's just more complex.
mod_rewrite is unnecessary overhead if the php codebase remains the same.
The $_SERVER array will still be filled, it can still be compared to
lightingly fast.
--
Rik Wasmus
Re: Better option than $_SERVER["HTTP_HOST"]
am 06.01.2008 17:34:06 von todofixthis
Heya, Jason.
If you find yourself doing this frequently, I would recommend
something like this instead:
[code=php]
$__domainInfo = explode('.', $_SERVER['HTTP_HOST']);
switch( $__domainInfo[0] )
{
case 'parkdomain1':
define('SUBDOMAIN', 'parkdomain1');
.
.
.
break;
case 'parkdomain2':
define('SUBDOMAIN', 'parkdomain2');
.
.
.
break;
default:
define('SUBDOMAIN', 'www');
break;
}
[/code]
and so on. It's a little cleaner, and faster than calling strpos()
more than 3 times.