So your question is how to assign the sub-domain? Well, if you are running on Apache (don't know about other servers), there are two main ways to do it:
- Have an email be sent to you when the user signs up, then manually configure the sub-domain.
- Have a PHP script that updates your httpd.conf file through fopen(), fwrite(), and fclose().
I prefer the second method, since it is automatic and doesn't require any manual configuration. However, this is dangerous, because one mistake could screw up the httpd.conf file and the server, so if you are going to do that, I EXTREMELY recommend testing the script on a different file first, before you put it into action. Also, you should regularly make back-ups of the file in case something happens.
If you are worried about any of this, I suggest using the first method, as it is a lot safer and more reliable, since it's harder for you to screw something up yourself, rather than through a bug in your script.