subdomain

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
rajan
Forum Contributor
Posts: 110
Joined: Sun Aug 28, 2005 7:42 pm
Location: Lucknow, UP, India

subdomain

Post by rajan »

how to create subdomain using php
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

Server? Operating system? Control Panel?
User avatar
dyconsulting
Forum Newbie
Posts: 14
Joined: Mon Dec 01, 2003 6:52 pm
Location: San Francisco

Creating subdomains using php

Post 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,
Post Reply