Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Php Programming Code Examples

Php > Miscellaneous Code Examples

Manage Virtual Subdomains

Manage Virtual Subdomains <?php /* Variables definitions */ $MySQLhost = "whatyouwant"; $MySQLuser = "whatyouwant"; $MySQLpsw = "Idonnow"; $MySQLdb = "yourdatabase"; /* Or another, it's the same */ $MyDOMAIN = "YourDomain.tld"; /* Put here you domain without WWW, */ $DefaultPage = "index2.html"; /* Put here the name of the default page */ /* Connectd to the DB */ mysql_connect ($MySQLhost, $MySQLuser, $MySQLpsw); mysql_select_db ($MySQLdb); /* Get the hostname typed in */ $subhost = strtolower($HTTP_HOST); /* Get away the "www." in front (in case there is one) */ $subhost = str_replace("www.", "", $subhost); /* Delete everything after (and including) the first "/" */ $subhost2 =strstr($subhost, "/"); /* Delete the domain in the string */ $subhost =str_replace($MyDOMAIN,"",$subhost); /* Delete dots */ $subhost =str_replace(".","",$subhost); /* If is something */ if(strlen($subhost)>0) { /* Query the DB with the current Subdomain */ $RSredirect = mysql_query ("SELECT * FROM domains WHERE subdomain='$subhost'"); /* Redirect if subhost exist */ if($Rredirect = mysql_fetch_array($RSredirect)) { header("Location: ".$Rredirect['destination']); exit; } /* Go to the default page */ else { header("Location: $DefaultPage"); exit; } } /* Go to the default page */ else { header("Location: $DefaultPage"); exit; } ?>