Forum Moderators: phranque

Message Too Old, No Replies

Creating Sub-domains with PHP/MySQL?

is this possible?

         

kawaiiultraneo

7:58 am on Mar 9, 2006 (gmt 0)

10+ Year Member



Hi there, I discovered this site purely by accident after searching for various string regarding this problem.
I've seen it done on another site... (Hmm.. dunno can I mention the site - IM me if you wanna know)

I would like to ask, would it be possible to use Mod Rewrite, or a PHP script to dynamically create sub-domain,
when a new user register to say a forum or something? I'm using vB at present. If it helps, I'm using a shared server.

Thanks in advance.

kawaiiultraneo

8:36 am on Mar 9, 2006 (gmt 0)

10+ Year Member



and or using ModRewrite. Sorry I have no access to httpd.conf

(hmm.. how i edit)

jdMorgan

11:51 pm on Mar 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



kawaiiultraneo,

Welcome to WebmasterWorld!

Yes it's possible, but there are many details that have to be taken care of. Here's a brief outline:

1) Make sure your host supports wild-card subdomains on your server.
2) Add an "A" record to your DNS zone file to define the wild-card subdomains.
3) Create a script that will validate new usernames (character-set must be limited to be sure that resulting URLs are valid).
4) The script should create a subdirectory to store the user's files.
5) Write some mod_rewrite code to rewrite (not redirect) subdomain requests to the users' subdirectories. (there are plenty of examples of that code here, do a search.)

I have not addressed issues like keeping users out of each other's directories, as the methods used would depend upon your specific requirements.

You will need a method to control how big each user's subdirectory can be; otherwise, you're likely to run into problems with your host if your site gets popular. Plan ahead.

Jim

kawaiiultraneo

5:26 am on Mar 10, 2006 (gmt 0)

10+ Year Member



Ah thanks for the reply Jim.

For the record, server-side coding ain't my strongest strength but it's something I'm whiling to learn, try, digest and maybe understand. Guess a idiots guide to writing mod-rewrite and php script would be good, right about now. Guess I'm saying I'm a noob.

Well anyway, I just checked with my host, it seems "A" is clearly set in all my present sub-domains and "MX" is set for mail.

However, I'm curious is there a secure way of doing this, whereby non-admins (or users) can't see into other users ftp/web accounts. With the exception of the site admin.

OK.. How and were do I start?
Jeez.. don't even know what this is called. :s

jdMorgan

1:57 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Our forum charter [webmasterworld.com] has a some useful links and information and links in it.

There are also the WebmasterWorld server-side scripting forums -- PHP and PERL.

Each forum also has a section in the WebmasterWorld Library [webmasterworld.com] -- A collection of the more useful posts.

There is no motivator quite so good as a current need, and you've got one.

This project is both more difficult than it seems (in identifying the technical details of what must be done), and simpler than it seems (only 4 lines of code in .htaccess or httpd.conf, and maybe a couple of pages worth of script code) maximum.

And you're right, learning the technical terms for things is part of the challenge. I'd call this project, "adding support for user-created subdomains."

Jim

kawaiiultraneo

10:54 am on Mar 11, 2006 (gmt 0)

10+ Year Member



Ah thank you for all the info, I'll go lookie. If i have any questions I'll post to this thread.

However, are there any commercial books you'd recommend for code Mod-rewrite and HTaccess, as a guide? I can't been to get my head around all the jargon plus, I'd like something I can read when not on the computer?

Currently, I find myself literally glued to this thing, even when I'm not working.

Cheers.

Laz