How to make site load on random subdomain??

Discussion in 'Programming' started by anteclimax, Dec 15, 2007.

  1. #1
    What I need is for each siteload to be on any random subdomain.

    If my site is www.domain.com then each time I visit www.domain.com/xyz , the url should be something like abc.domain.com/xyz then dfg.domain.com/xyz and so on basically random.domain.com/xyz


    Any help would be appreciated.
     
    anteclimax, Dec 15, 2007 IP
  2. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #2
    1) Create folder in your domain.com, called xyz.
    2) Inside that folder, create an index.php with the following code:

    
    $domain_name = 'phptricks.com/xyz';
    $list_subdomains = array('abc','dfg');
    
    srand((double)microtime()*1000000);
    $random = rand(0,count($list_subdomains)-1);
    
    header("Location: http://".$list_subdomains[$random].$domain_name);
    exit();
    
    PHP:
    Peace,
     
    Barti1987, Dec 15, 2007 IP
    anteclimax likes this.
  3. anteclimax

    anteclimax Active Member

    Messages:
    100
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    60
    #3
    I dont understand php, but I assume that the code will create a cotainer with my specified subdomain names, ie. abc ,dfg and so on. then it will progessively change my subdomain name?

    Can you change the code and make it completely random, ie instead of me specifying a list of subdomains, the code will generate a random alphanumeric subdomain each time?
     
    anteclimax, Dec 16, 2007 IP