A little script that help you create virtual subdomains in your internet domain with Wild Cards allowed.
By : dr.Freud
<?php /* ******************************************************** * Manage Virtual Subdomains * * developed by: Jacopo Agnesina <dr.freud@agnesina.it> * ******************************************************** - Requirements: PHP 4.2.2 [tested-on-it], MySQL 3.23 [tested-on-it], a domain with wildcards allowed! [contact your sysamdin for info] ********************* - Database details - ********************* TABLE: domains FIELDS: subdomain (char[255], Primary, Not Null); * Contain the subdomain that you to associate to an url. destination (char[255], Not Null); * The url where the browser will be redirected when you query the sub domain above. popup (tinyint[1], Not Null, default -> 0); * For future implementation description (text); * For future implementation ********************************** * FREE YOUR CODE, FREE YOUR MIND * ********************************** */ /* 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, for example "codewalkers.com" */ $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; }
?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.