Miscellaneous Code

  Home arrow Miscellaneous Code arrow Manage Virtual Subdomains
MISCELLANEOUS CODE

Manage Virtual Subdomains
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-08-06

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    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.

    More Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap