retrieve subdomain as a get variable
问题 Hi guys I'm setting up mywebapplication to give unique urls for users such as uniquename.mysite.com, anotheuniqname.mysite.com etc. I want to be able to in a php script grab the subdomain part of the url. Would be nice if I can get it as a GET variable - I think it can be done with htaccess. Any ideas? 回答1: $subdomain = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.')); To make sure there's a valid subdomain: $urlExplode = explode('.', $_SERVER['HTTP_HOST']); if (count(