Adam McArthur
Adam McArthur

Reputation: 980

Detecting if a user is coming from a subdomain in Smarty PHP

So I'm using WHMCS for my hosting website, and I've created a subdomain that also runs WHMCS. (EG: mydomain.com is the hosting site, then I have a subdomain like designs.mydomain.com).

As I said, both domains run WHMCS, and therefore show the exact same websites when you visit them. The subdomain is linked to WHMCS which is a directory back from its location (it hasn't just been copied).

The Question:

Now, I want to set WHMCS to run a different template on the subdomain, but to do that I need to somehow detect with Smarty PHP weather a user is on the sub domain, or the normal domain?

Is it possible to do this, and if so how?

Thanks :)

Upvotes: 0

Views: 789

Answers (1)

rodneyrehm
rodneyrehm

Reputation: 13557

PHP supplies the current hostname in $_SERVER['HTTP_HOST']. Smarty maps {$smarty.server} to $_SERVER (like it maps any other superglobal (_GET, _POST, _COOKIE, _SESSION, …)). So you can try the following:

{if $smarty.server.HTTP_HOST == "designs.mydomain.com"}
  I was called from the subdomain designs.
{else}
  I was not called from the subdomain designs. 
  maybe via the regular domain or some other subdomain
{/if}

Upvotes: 1

Related Questions