J.me

Fake sub-domain in 1..2..3

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. 🙂

2 comments | Leave a comment

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.