create dynamic sub domain

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sethupnr
    New Member
    • Sep 2007
    • 26

    create dynamic sub domain

    i wish to make a site(http://example.com) and allow user to create their own site under http://example.com. When a user register in my site automatically generata a subdomain for that user. thatis http://user1.example.c om. The actual files of the user in my server look like this /wwwroot/userfiles/user1. and also i have to make a small banner on each file,user uploaded. Can u help me?
  • eragon
    Contributor
    • Mar 2007
    • 431

    #2
    [PHP]<? function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolo wer($_SERVER["SERVER_PROTOCO L"]), "/").$s; $port = ($_SERVER["SERVER_POR T"] == "80") ? "" : (":".$_SERVE R["SERVER_POR T"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } ?>[/PHP]

    put that out of the way somewhere, it basically splits your URL.
    [PHP]<?
    $url = explode("://", selfURL());
    $url2 = explode(".", $url[1]);
    $sub = $url2[0];
    if($sub != "yourDomain ") {
    header('locatio n: http://yourDomain.com/'.$sub); } ?>[/PHP]

    and theres a redirect, replace all instances of yourDomain with the part BEFORE the .com and AFTER the http:// (Or other respective piece of text). $sub will be your username. put thie BEFORE any html output. including php echoes.

    if you have any questions pm me or post here.

    Comment

    • sethupnr
      New Member
      • Sep 2007
      • 26

      #3
      where i place these php codes? Can u explain in details..
      and thanks for ur help.

      Comment

      • eragon
        Contributor
        • Mar 2007
        • 431

        #4
        i am extremely sorry. i forgot to finish the post

        place these codes in the index.php page that you get when you first load your website. Place them at the top of your very first page, and adjust the URLs accordingly.

        this way, when the page loads, it checks the URL, and when it sees the subdomain, it will re-direct to the folder with that domain as it's name. if there is no sub domain it keeps you on your home page.

        See if this helps

        Comment

        • sethupnr
          New Member
          • Sep 2007
          • 26

          #5
          ya i did these things. But i didnt get the output. Plz giv the step by step instruction,if u can.

          Comment

          • eragon
            Contributor
            • Mar 2007
            • 431

            #6
            did you get an error from the browser... if so, post it. i'm going to put a seperate page on my website with this script in it to test it. ill post my results and instructions.

            Comment

            • eragon
              Contributor
              • Mar 2007
              • 431

              #7
              here is the link to the installation page.

              maybe this will clairify things

              Comment

              • sethupnr
                New Member
                • Sep 2007
                • 26

                #8
                i used this code in my index.php

                <? function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
                $protocol = strleft(strtolo wer($_SERVER["SERVER_PROTOCO L"]), "/").$s;
                $port = ($_SERVER["SERVER_POR T"] == "80") ? "" : (":".$_SERVE R["SERVER_POR T"]);
                return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
                }
                function strleft($s1, $s2)
                { return substr($s1, 0, strpos($s1, $s2));
                }

                $url = explode("://",selfURL() );
                $url2 = explode(".", $url[1]);
                $sub = $url2[0];
                //print $sub;

                if($sub != "example") {
                header('locatio n: http://example.com/'.$sub); }
                ?>

                and also i created one account "user1"
                when am using http://example.com it prints " example"
                but when i'm using http://user1.example.c om it didnt print "user1" and 403 forbidden appeared in the browser.

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Originally posted by eragon
                  here is the link to the installation page.

                  maybe this will clairify things

                  http://player-killer-clan.110mb.com/dsd.php?home.php
                  A very sloppily written code, i must say.

                  Comment

                  • eragon
                    Contributor
                    • Mar 2007
                    • 431

                    #10
                    the 403 is as i expected. your server is treating the user1.example.c om as an actual subdomain, and anything before your server is handled as part of an actual subdomain, not passed to the page, so im stuck there. and yes, i know, the code is sloppy, all my codes are, but it all works just the same.

                    have the people in the htaccess forum help you out, tihs goes beyond my knowledge

                    thank you anyway.

                    Comment

                    Working...