Page 1 of 1

subdomain

Posted: Thu Sep 22, 2005 12:33 pm
by rajan
how to create subdomain using php

Posted: Thu Sep 22, 2005 2:01 pm
by Buddha443556
Server? Operating system? Control Panel?

Creating subdomains using php

Posted: Thu Sep 22, 2005 5:41 pm
by dyconsulting
This can easily be done without a need to create a virtual host or make any server configurations.
Let’s say you want each member have his own subdomain, say: user1.sitename.con, user2.sitename.com, etc.

Here are the steps:

1. Change DNS record to resolve your domain to http://* (anything after http will be resolved to your domain name). You only need to do this if you want your users to type http://user1.sitename.com instead of http://www.user1.sitename.com

2. Have code in shared library which will be run on top of every page. This code will do the following:
a. it will parse the url and get subdomain postion of the domain
you can then preserve this info in a session if you like, so you don’t need to parse the url each time.
b. What you do with this info is up to you. For example you can use it to show personalize content.

I am not providing any code here because it very simple. All you have to do is split a url and "pull" only the part that you need. Make sure you handle domain with both http://www.sub.domain as well as sub.domain.com.

Take care,