|
PHP: get subdomain from host<?php
$subdomain = substr_count($_SERVER['HTTP_HOST'], '.') > 1 ? substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.')) : '';
// Where host is 'www.example.com' $subdomain will be 'www'
// Where host is 'example.com' $subdomain will be ''
// Where host is 'sub2.sub1.example.com' $subdomain will be 'sub2'
// Where host is 'localhost' $subdomain will be ''
|