#native_company# #native_desc#
#native_cta#

Virtual Hosting in PHP

By Shawn White
on February 4, 2002

For those of you who host multiple sites on your server but only have one ip, and no dns server. Maybe your hosting on your home dsl line and using a third pary dns / ip based forwarding (such as DNS central) but you need the page requests redirected to different folders depending on what was typed in the browser address bar.
You also want the address in the browser to remain unchanged.


<?
//Virtual hosting via php by Shawn White at [email protected]
//Free to use modify copy etc. If it helps you in someway a thank you email would be nice.
//Modify this array to add your own sites
//First elemement of the array is the site the
//visitor typed in addressbar, second element
//is where you //want to route them.
//leave out the http and www in the key(the first element)  - this is already dealt with
$websites=array(
"plantworldnursery.com"=>"/plantworld/",
"jackvalenti.net"=>"http://www.2600.com",
"hollywood.emailbiz.org"=>"http://www.emailbiz.org/users/hollywood/");
$defaultsite="http://www.emailbiz.org/emailbiz.html";
$homepageonly="no"; //this will may sure requests for any page other than the home page goes to the homepage anyway 

//Do not modify anything below this line!
$siterequested=getenv("HTTP_HOST");
$extrapages=getenv("REQUEST_URI");
$sitefound="false";
foreach($websites as $key=>$value)
{
$sitepos=strpos($siterequested,$key);
if($sitepos >-1)
		{
			$sitefound="true";
			if($homepageonly=="yes")header("Location:$value");
			else
			{
			$cloc=$value . $extrapages;
			header("Location:$cloc");
			}
	  }		
}//end of foreach
if($sitefound=="false") header("Location:$defaultsite");
?>