So iv'e been trying to find the right path for me for my situation but couldn't just find the right answer.
So what i need to do is a php script that will create a subdomain that redirects to an IP that will be sent from my post request.
Example -
I post to script.php - ?username='test'&ip='127.0.0.1'
I need this post request to create a subdomain with this username(the username will be used for the subdomain - test.mysite.com
visiting test.mysite.com will redirect to 127.0.0.1
What im trying to achive is something like a dns service.
Is it possible? Do i need to ask my host for something(Godaddy/IIS Server)
Thanks ! Really appreciate any lead.
Asked
Active
Viewed 602 times
0

Yarden A.
- 13
- 6
1 Answers
0
This requires 3 steps:
- You need to create a wildcard DNS entry for subdomains of your domain
*.example.com A 192.0.0.10
- You then need to setup a new vhost entry for your apache server. This should come after the vhost entry for your existing server, if it's running on the same machine as this subdomain redirection system.
NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /var/www ServerName www.example.com ServerAlias *.example.com </VirtualHost>
- Finally, you write your index.php script to get
$_SERVER['HTTP_HOST']
and based on that, to do a lookup in the database for your subdomain name, and send the header('Location:') based on a successful lookup in the database.

gview
- 14,876
- 3
- 46
- 51
-
This assumes that you have a script, that stores the domains in a database. You need something a table with a structure like id, domain, redirect. The redirect can be an IP or hostname. The *.example.com entry needs to point to YOUR publicly accessible server where your PHP script is going to run. – gview Dec 01 '13 at 03:01