Forum Moderators: coopster

Message Too Old, No Replies

Assign current subdomain to php $variable

Using PHP to get the current subdomain and assign it to a variable.

         

njo86

6:13 pm on Oct 31, 2009 (gmt 0)

10+ Year Member



Hey all,

I've spent some time now looking for an answer to this and I'm at a dead end..

Basically, I'm trying to assign a web page's current sub-domain to a PHP variable.

Example:
[hello.website.com...]

I want 'hello' to be assigned to $subdomain so that throughout the page I can use $subdomain to generate data specific to that subdomain.

I'm not looking to map sub-domains to specific content or anything like that as that is already functioning but I just need to make the sub-domain into a variable that I can use throughout the page.

Any suggestions/ideas would be very much appreciated!

Thanks
Nic

homeless

6:32 pm on Oct 31, 2009 (gmt 0)

10+ Year Member



$host_exp = explode('.', $_SERVER['HTTP_HOST']);
if(count($host_exp) == 3) $subdomain = $host_exp[0];

njo86

7:19 pm on Oct 31, 2009 (gmt 0)

10+ Year Member



Amazing!
You're a star.

Very much appreciated.

Cheers
Nic