View Full Version : Variable: HTTP_HOST (changes text on page)?
Chicken
05-07-03, 05:43 AM
OK, here's what I would like to know from people who know php. Right now, I have a statement (if that's what you'd call it), that basically changes the style of the pages, depending on HTTP_HOST.
if(GETENV("HTTP_HOST")=="bobsclambake.com")
{
$styleid = 2;
}
What I'd like to know is, that instead of dictating the style, there is a way to use HTTP_HOST as a variable to display different text. So on a php page, I'd like somethign more like this (not coded correctly):
if(GETENV("HTTP_HOST")=="bobsclambake.com")
{
<display this text>
Hi, welcome to Bob's Clam Bake. Blah blah
if(GETENV("HTTP_HOST")=="SuziesPuppies.com")
{
<display this text>
Hi, welcome to Suzie's Puppies. Blah blah
}
I'm not sure it would be possible to have a default even, but I would think that you may need to include all posible HTTP_HOST (including HostHideout.com) or when users came from HostHideout.com they might not see anything. They should see, "Hi, welcome to HostHideout. Blah blah"
So first, is this possible (display text based on HTTP_HOST), and second, the coding for multiple HTTP_HOST 's). Hopefully this makes sense!
Chicken,
You can do what your doing with a simple case and switch statement. It will take care of all possibilities by offering a defualt answer too.
I really dont understand the purpose of the use of HTTP_HOST?
kunal
Chicken
05-07-03, 02:46 PM
Because it si the URL (domain name) that I need to be the variable. I have the forum set up for a co-brand (as in findspforums.com), but I'd like to explore a few ways of doing it before offering it. So I need a default for HostHideout.com (in case people type it in or come to here via a link), and a variable statement that can handle more than one URL (so that when anotherdomain.com is the URL typed in it displays text unique for that URL).
not sure, but what if..
if(GETENV("HTTP_HOST")=="bobsclambake.com"){
require("bobslambake.php");
} elseif(GETENV("HTTP_HOST")=="SuziesPuppies.com"){
require("SuziesPuppies.php");
Than make those your "index" pages with the custom results?
interactive
05-07-03, 05:17 PM
Just do a if-else statement (simpler) or as Kunal suggested, a switch-case.
Chicken
05-07-03, 10:26 PM
Originally posted by Robert:
Than make those your "index" pages with the custom results?
I don't want to link to a unique page. I need it to just change what will be displayed on one page, in a certain area (the top). So the logo will appear differently, etc.
Originally posted by interactive:
Just do a if-else statement (simpler) or as Kunal suggested, a switch-case.
Ah, that explains it. :)
That can be done pretty easily. Try your head around this code:
<?
$comeFrom = $HTTP_HOST;
switch($comeFrom) {
case 'domain1.com': $headerContent = "XXX";
break;
case 'domain2.com': $headerContent = "YYY";
break;
default: $headerContent = "Host Hideout Header";
}
echo $headerContent
?>
Is that what your saying?
kunal
It's customary to put a break; after the default line too. I seem to remember my CS lecturer shouting at me for not including one once.
S3G
Chicken
05-09-03, 05:50 AM
Well, understand that even if you post something I probably won't know if it is right or will work, heh. But willing to try! That seems right Kunal, so long as:
default: $headerContent = "Host Hideout Header";
Can actually be much longer (as in lines and lines of HTML, not just one word). That would work for changing a logo though at least maybe.
Yup, the text within the " " can contain anything. :)
You know what, just IM me or something, and we can work it out ;)
kunal
One potential problem is the www.domain.com and domain.com differences.
<?
$domain = GETENV("HTTP_HOST");
$first = strpos($domain, '.');
$second = strpos($domain, '.', ($first+1));
if (!$second)
{
$domain = substr($domain, 0, $first);
}
else
{
$domain = substr($domain, ($first+1), ($second - $first -1));
}
?>
This will return just 'domain'.
HTH
S3G
Chicken
05-09-03, 04:27 PM
But if you have www.domain.com CNAMED to domain.com then it would probably work fine. I have it this way now and it seems to work.
Interesting, that's how I have my test server set up but phpinfo() reports either www.something.net or something.net depending on which I use. Perhaps it's a version, a php.ini thing or neither? Anyway if it work it works :cool:
S3G
vBulletin v3.5.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.