Connecting Tech Pros Worldwide Forums | Help | Site Map

How to create subdomain(s) dynamically for user registration?

Newbie
 
Join Date: Sep 2009
Posts: 13
#1: Sep 27 '09
When each new user tries to register, a directory on the server will create for her/him. (www.example.com/user_name)
but as you know I need her/him directory to be available as follows too (http://user_name.example.com/).

I have Linux Server.It's not a local project, so the _conf file of Apache Server may not accessible at all. I need a working .htaccess code etc. or something else.

Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#2: Sep 27 '09

re: How to create subdomain(s) dynamically for user registration?


look at the mod_rewrite cheat sheet. it's one of the examples there.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#3: Sep 27 '09

re: How to create subdomain(s) dynamically for user registration?


Hm, I strongly doubt you can do that without having access to the server configuration.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,648
#4: Sep 27 '09

re: How to create subdomain(s) dynamically for user registration?


.htaccess can do it. (I know because I use it)
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#5: Sep 27 '09

re: How to create subdomain(s) dynamically for user registration?


Quote:

Originally Posted by Dormilich View Post

.htaccess can do it. (I know because I use it)

Care to give an example? I looked through that link you supplied, but couldn't find anything on 'faking' a subdomain.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#6: Sep 28 '09

re: How to create subdomain(s) dynamically for user registration?


I found this a while back, but never tried it out:
Expand|Select|Wrap|Line Numbers
  1. RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
  2. RewriteRule .* http://domain.com/somescript.php?var=%1 [R,L]
The reason I didn't try it out is because "you need to set up foo.domain.com's DNS entry to go to your server's IP address. Also you need your server properly configured to show the contents of domain.com's DocumentRoot when foo.domain.com is requested." - Sounded like work, but I might give it another go now that I know more. Let us know how you go!
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,938
#7: Sep 28 '09

re: How to create subdomain(s) dynamically for user registration?


Quote:

Originally Posted by TheServant View Post

I found this a while back, but never tried it out:

Expand|Select|Wrap|Line Numbers
  1. RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$
  2. RewriteRule .* http://domain.com/somescript.php?var=%1 [R,L]
The reason I didn't try it out is because "you need to set up foo.domain.com's DNS entry to go to your server's IP address. Also you need your server properly configured to show the contents of domain.com's DocumentRoot when foo.domain.com is requested." - Sounded like work, but I might give it another go now that I know more. Let us know how you go!

Which requires access to the server configuration.

Mark.
Newbie
 
Join Date: Oct 2009
Posts: 1
#8: Oct 14 '09

re: How to create subdomain(s) dynamically for user registration?


hello - I found this thread and I search do to something similar
so I want to show online users that I get them from xml source and it show like that
Expand|Select|Wrap|Line Numbers
  1. <?
  2.     default :
  3.         $xml_source = 'http://www.site.com/xml/users.xml';
  4.         $site_url = 'http://www.site.com/users/';
  5.  
  6. // ---- if we got some data, then try to parse it
  7. if ( $xml_content = file_get_contents( $xml_source ) ) {
  8.  
  9.     $xml_parser = xml_parser_create();
  10.     xml_parse_into_struct( $xml_parser, $xml_content, $value, $full_index);
  11.     xml_parser_free( $xml_parser );
  12.  
  13.  
  14.     $items = array();
  15.     foreach ( $value as $current_value ) {
  16.         if ( $current_value['level'] == 3 ) {
  17.             $items[] = $current_value;
  18.         }
  19.     }
  20.     reset( $items );
  21.  
  22.  
  23.     $item_count = count( $items );
  24.     $users = array();
  25.     for ( $i = 0; $i < $item_count; $i += 2 ) {
  26.  
  27.         $current_user_name = each( $items );
  28.         $current_category = each( $items );
  29.         $users[ strtolower( $current_category['value']['value'] ) ][] = $current_user_name['value']['value'];
  30.  
  31.     }
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.     // ---- If we got category parameter, then show just that part of the array
  39.     if ( isset( $_GET['category'] ) && !empty( $_GET['category'] ) && isset( $users[ strtolower( $_GET['category'] ) ] ) ) {
  40.         $category = $_GET['category'];
  41.     }
  42.  
  43.     if ( $category !== null ) {
  44.         $category = strtolower( $category );
  45.         $new_users = $users[ $category ];
  46.         $users = array();
  47.         $users[ $category ] = $new_users;
  48.     }
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.     // ------- OUTPUT
  57.     if ( $table_output ) {
  58.  
  59.         // ---- how many users should be in one column
  60.         if ( $users_count = count_users( $users ) ) {
  61.             $max_rows = ceil( $users_count / 7 );
  62.         } else {
  63.             $max_rows = 0;
  64.         }
  65.  
  66.  
  67.         echo '<table width="100%" cellspacing="0" cellpadding="0" border="0">' . "\n";
  68.         echo '    <tr>' . "\n";
  69.         echo '        <td valign="top">' . "\n";
  70.  
  71.     }
  72.  
  73.  
  74.     $current_user_number = 0;
  75.     foreach ( $users as $current_category => $users_in_category ) {
  76.         sort( $users_in_category );
  77.  
  78.         // ---- in "table_output" mode we don't need category name.
  79.         if ( ! $table_output ) {
  80.             // ---- Print category name
  81.             echo $current_category . ' (' . count( $users_in_category ) . ')<br>' . "\n";
  82.         }
  83.  
  84.         foreach ( $users_in_category as $current_user ) {
  85.  
  86.             if ( $table_output ) {
  87.  
  88.                 // ---- if the user count is bigger than the allowed number in one column, then we break the list into a new column
  89.                 if ( $current_user_number > $max_rows ) {
  90.                     $current_user_number = 0;
  91.  
  92.                     echo '</td>' . "\n";
  93.                     echo '<td valign="top">' . "\n";
  94.  
  95.                 }
  96.  
  97.             }
  98.  
  99.             echo '<a href="' . $site_url . '' . $current_user . '" ><span class="user_name">' . $current_user . '</span></a>' . "\n";
  100.             if ( $show_category_name ) {
  101.                 echo '&nbsp;<span class="user_category">' . $current_category . '</span>';
  102.             }
  103.             echo '<br>';
  104.  
  105.             // ---- increase user count in the current column
  106.             $current_user_number++;
  107.  
  108.         }
  109.  
  110.     }
  111.  
  112.  
  113.     if ( $table_output ) {
  114.  
  115.         echo '        </td>' . "\n";
  116.         echo '    </tr>' . "\n";
  117.         echo '</table>' . "\n";
  118.  
  119.     }
  120.  
  121. } else {
  122.  
  123.     echo 'Error while trying to open the XML file.';
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133. /**
  134.  * Count all the users in the users array
  135.  *
  136.  * @param array $users_array
  137.  * @return int
  138.  */
  139. function count_users( $users_array ) {
  140.  
  141.     $ret = 0;
  142.     if ( is_array( $users_array ) && count( $users_array ) > 0 ) {
  143.  
  144.         foreach ( $users_array as $current_category => $users ) {
  145.             $ret += count( $users );
  146.         }
  147.  
  148.     }
  149.  
  150.     return $ret;
  151.  
  152. }
  153.  
  154.  
  155. ?>
this will show online users like

http:// www . site.com/users/user-name

and I want to show the online users like

http:// user-name.site.com

Can anyone help me sort this out ?

thank you
Reply

Tags
dynamic subdomain, php