Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By kvarnelis on
sorry folks, just haven't been able to find this on google.
i want to use php to identify what domain the user is coming from.
not what path, what domain.
imagine you had three subdomains all pointing to the same page.
is it happy.drupal.org, sad.drupal.org, or drupal.org?
depending on which it is, the user gets a message.
how could you create php conditional responses for those subdomains?
Comments
hostname via php
i believe what you are looking for is the HTTP_HOST index of the $_SERVER global.
excellent! that worked.
excellent! that worked. thank you kurpishuz !!
ok. dumb question coming up. really dumb. please get ready.
i want to use this code to determine the front page of my site.
serve up one if you come in via the subdomain (chipper.kittens.com).
serve up another if you come in via the regular domain (kittens.com).
so the simple thing to do will be to use a bit of code like that above to decide what will be output, right?
right!
but i already have my phptemplate the domain built.
if i create php branching code, won't I have to rewrite the entire page to replace html statements with php versions of those statements?
a total pain!
isn't there any way that i can wrap the code of a phptemplate (which of course has php within it!) in such a way that it is evaluated as php laden html, not as html laden php? and of course, do this in a php fork of
if
then
else
?
ok, that was really easy.
ok, that was really easy. for the benefit of others...
if($_SERVER['HTTP_HOST'] == 'chipper.kittens.com :
meow
else :
woof
endif;
you can see the results at
kazys.varnelis.net
this allows me to preserve the blog at varnelis.net, which by now has a bit of a following, but since the blog page is getting a little cluttered and hard to navigate, it allows me to create a new home page based on that subdomain.
caveat
this will not work with cache enabled.
most current versions of drupal break this
not sure what happened but somewhere in the migration to 4.7.2, this got broken. it looks like it went away during the last cycles of the beta or the rc's but not sure where.
http://www.varnelis.net