Forum Moderators: coopster

Message Too Old, No Replies

How to simplify this?

         

Laibcoms

11:03 am on Jul 16, 2007 (gmt 0)

10+ Year Member



Hi,

Are there other ways to shorten this code so I can avoid multiple HTTP_HOST calls?


if ($_SERVER['HTTP_HOST'] == "example.com.sg") {
stuff here
}
elseif ($_SERVER['HTTP_HOST'] == "example.com.my") {
stuff here
}
else {
stuff here
}

I am thinking on the line of:
$browserurl = $_SERVER['HTTP_HOST'];

<a href="subdomain.'; $browserurl;'/subfolder/etc/">

I tried switch-case, but stuck on the same
I want to simplify it for the use of the none-techy editors of our news page, since I can't be available all the time :p

Thanks all!

[edited by: eelixduppy at 2:17 pm (utc) on July 16, 2007]
[edit reason] example.com [/edit]

Habtom

11:12 am on Jul 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are there other ways to shorten this code so I can avoid multiple HTTP_HOST calls?

if ($_SERVER['HTTP_HOST'] == "example.com.sg") {
stuff here
}
elseif ($_SERVER['HTTP_HOST'] == "example.com.my") {
stuff here
}
else {
stuff here
}

$ht_host = $_SERVER['HTTP_HOST'];

if ( $ht_host== "example.com.sg") {
stuff here
}
elseif ($ht_host == "example.com.my") {
stuff here
}
else {
stuff here
}

[edited by: eelixduppy at 2:19 pm (utc) on July 16, 2007]
[edit reason] example.com [/edit]

Laibcoms

2:32 am on Jul 17, 2007 (gmt 0)

10+ Year Member



Ahh... I didn't thought of that ^^;

Hmm... how about something like:

<a href="subdomain.' $ht_host; '/subfolder/">

I tried it out but won't work.

Thanks again!

vincevincevince

2:42 am on Jul 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




switch ($_SERVER['HTTP_HOST'])
{
case "example.com.sg" :
{
stuff here
break;
}
case "example.com.my" :
{
stuff here
break;
}
default :
{
stuff here
break;
}

And for this:

<a href="subdomain.' $ht_host; '/subfolder/">

Use:
<a href="subdomain.'.$ht_host.'/subfolder/">