I just figure this out, thanks for Google’s help. :) If you want to have fake sub-domain, which do nothing but to send request to your PHP script, so you don’t need to use separate script for each sub-domain, then this might be the simplest way to do. Yup, as easy as 1, 2, and 3……. lol

Okay, so this is how:

1. Create a sub-domain and fill the name with single “*” (without quotes). For example *.mydomain.com. Specify your sub-domain directory if you want, I use “sub”, so when there is (unknown) sub-domain called, it will automatically call the script in mydomain.com/sub.

2. Then add this piece of code to retrieve the sub-domain name.

$subdomain = preg_replace(”/^([\w-]+)\..*$/”, “\\1″, $_SERVER['HTTP_HOST']);

3. Done!!! Now you can process your script easily when you know the sub-domain. :)

If you like this article, share it
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks