www.webdeveloper.com
Results 1 to 5 of 5

Thread: Is it possible to create subdomains using php

  1. #1
    Join Date
    Sep 2004
    Location
    Sri Lanka
    Posts
    473

    Is it possible to create subdomains using php

    Hi,

    I d like to know about the possibility of creating subdomains using php . Even an alternative would help until it helps to have the url format, http://subDomainOrAlias.domain.com

    BR

  2. #2
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    The answer is probably yes.

    Do you want a PHP script that will update DNS records for you? Or, do you want a PHP script that will "forward" HTTP requests to the appropriate files/scripts based on the HTTP Host header?

    If you're looking for the 1st option ... umm ... find a DNS service with a nice API and let us know how it turns out

    If you're looking for the 2nd option, see the HTTP_HOST environment variable: http://www.php.net/manual/en/reserve...les.server.php


    EDIT: In regards to the 2nd option, the assumption is that you've set up a wildcard host: *.yourdomain.com A <your apache server's IP>

  3. #3
    Join Date
    Sep 2004
    Location
    Sri Lanka
    Posts
    473
    Thanks for the info.. I will try for both . Btw would you be able to post a sample or link to a code sample how wild card host

    BR

  4. #4
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    Set up a wildcard host -- ask your hosting provider for help with their DNS control panel if you're not sure how to do this. And then start with something like this:
    PHP Code:
    <?php
    $valid_hosts 
    = array(
      
    'host1',
      
    'host2',
      
    'host3'
    );

    if (
    in_array($_SERVER['HTTP_HOST'], $valid_hosts)) {
      require(
    $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    } else {
      require(
    '404.inc');
    }
    ?>
    Make sense?

  5. #5
    Join Date
    Sep 2004
    Location
    Sri Lanka
    Posts
    473
    Thanks for the informative reply.

    BR

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles