Archive

Archive for December, 2008

Users and Subdomains

December 11th, 2008 No comments

Some months ago the company I work for needed a special feature that I think is very common at web services. The idea is to offer users their own subdomains. It is pretty much like this blog system.

The idea is that all subdomains point to the same location on your server. You can then fetch user data from a database using the subdomain name as a key. We use a lot of PHP here so our key would be something like $_SERVER['DOMAIN_NAME'].

I first thought of building a small script at the server to manage the subdomains. List, add and delete. Boring.

The server for this system had cPanel installed. It is a good tool but it took me a while to find out I could handle all subdomain errands with CPanel’s XML API. The documentation is very poor and lack details. By the time of this writing you don’t even have a complete list of methods for the subdomains:

CPanel API

You can see here that the only method listed is for deleting Subdomains. Too bad. Lost some precious time digging cPanel code.

Anyway, here’s a simple class that you can use to list, add and delete subdomains if you have cPanel installed on your server.

You’ll probably need to adapt the code to your needs and enforce error checking.

cpanel.tar