SitePoint Forums

SitePoint Forums (http://www.sitepoint.com/forums/index.php)
-   PHP (http://www.sitepoint.com/forums/forumdisplay.php?f=34)
-   -   Can PHP use this subdomain technique? (http://www.sitepoint.com/forums/showthread.php?t=275584)

mrtopher Jun 26, 2005 11:34

Can PHP use this subdomain technique?
 
I recently found and became a fan of the online project management system Basecamp. I noticed that when you begin using their system, they hook you up with a subdomain like http://cmwebdandd.clientsection.com. This subdomain then remains with you throughout the program.

After doing some research I found that the program takes the subdomain part (cmwebdandd from above) and then goes into the database and populates the program with my information (using it like primary key to get my information out of the database). Is it possible to use this same technique with PHP and if so, how?

mark_W Jun 26, 2005 11:40

Yeah, I cant see why that wouldn't be possible with php. You couldn't actually create the sub domains with php though. You could create sub folders under the web root and then use mod rewrite to make them appear as sub domains though.

Sorccu Jun 26, 2005 12:08

Sure is.

PHP Code:

if (preg_match("/^([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-]+)\.([a-zA-Z]{2,5})$/",$_SERVER["SERVER_NAME"],$matches))
{
  list(
$subdomain,$domain,$tld) = $matches;
}

You could improve the pattern a bit, though :)

Kings Jun 26, 2005 12:49

It isn't really about whether PHP can do it, but if your server is able to do it. What you need is something called wildcard DNS (or wildcard sub domains). If you've got a regular cPanel account, then you probably won't be able to do it.


All times are GMT -7. The time now is 00:28.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved