You need to generate a subdomain when you click on the button ( случайный-поддомен.site.com ). Here is the string generator:

 function rand_string( $length = 8, $repeat = false, $UpperCase = true, $LowerCase = true, $Symbols = true, $SymbolsList__ = '0123456789-', $UpperCaseList = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', $LowerCaseList = 'abcdefghijklmnopqrstuvwxyz') { if ($UpperCase) { $UpperCase = $UpperCaseList; } if ($LowerCase) { $LowerCase = $LowerCaseList; } if ($Symbols) { $Symbols = $SymbolsList__; } unset($UpperCaseList, $LowerCaseList, $SymbolsList__); switch (rand(0, 5)) { case 0: $All = $UpperCase . $LowerCase . $Symbols; case 1: $All = $UpperCase . $Symbols . $LowerCase; case 2: $All = $Symbols . $LowerCase . $UpperCase; case 3: $All = $Symbols . $UpperCase . $LowerCase; case 4: $All = $LowerCase . $Symbols . $UpperCase; case 5: $All = $LowerCase . $UpperCase . $Symbols; } unset($UpperCase, $LowerCase, $Symbols); $totalLength = strlen($All) - 1; if (!$repeat) { $totalLength++; if ($length > $totalLength) { // echo "Error while generating the string: the maximum length is exceeded ($length instead of $totalLength characters)"; return false; } $totalLength--; while ($i++ < $length) { $Current = $All{rand(0, $totalLength--) }; $All = str_replace($Current, '', $All); $string.= $Current; } } else { while ($i++ < $length) { $string.= $All{rand(0, $totalLength) }; } } unset($All, $i, $length, $totalLength, $repeat); return $string; } echo rand_string() 

Suppose the generated value is lhtjnz23 . How to assign this value to the domain .site.com so that it is lhtjnz23.site.com ?

  • specify the question - what do you want to do? - gecube 7:47 pm

2 answers 2

htaccess :

 <IfModule mod_rewrite.c> RewriteEngine On Options +FollowSymlinks RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^.*$ index.php [NC,L] </IfModule> 

index.php :

 $params = array(); $t = explode(".", $_SERVER["HTTP_HOST"]); $subdomain = $t[0]; echo "You asked me subdomain: '$subdomain'"; 

Total we have:

  1. server with mod_rewrite enabled
  2. .htaccess file with query redefinition
  3. file index.php, designed to handle all requests to the site

And how to make routing, etc. etc. think for yourself

Sources:

  1. phpinfo.su. CNC in PHP
  2. Own head with a little PHP knowledge
  • When I requested classes.localhost, the browser gave the message You asked me subdomain 'classes' =) - garmayev

As I understand it, you need to break with the so-called CNC (Human-Intelligent URL). As an example, you can see the article http://www.phpinfo.su/articles/practice/chpu_na_php.html

This article focuses on working with URIs in particular. Ram, on the other hand, needs only to separate the site name into a subdomain.domain.zone using the explode command by the symbol "."

  • I need to insert from rand_string () into "subdomain" .site.com subdomain- generated by generator - 111ping
  • after generation use header? - garmayev
  • For example, ** header ("Location: http: \\". Rand_string. ". Domain.com \"); Did I understand you correctly? and then process everything as CNC? Now I will try everything, I will report the results - garmayev