PHP - How do you create sub domains using PHP?

How do you create sub domains using PHP?

- Wild card domains can be used. Sub domains can be created by first creating a sub directory in the /htdocs folder. E.g. /htdocs/mydomain. Then, the host file needs to be modified to define the sub domain. If the sub domains are not configured explicitly, all requests should be thrown to the main domain.

Following are the steps:

1. Set the main domain to act as a catch-all domain. Like if the main domain root is /home/admin/xyz.com/htdocs/ then the catch all setup sends all the sub-domain requests to the same directory i.e. /home/admin/xyz.com/htdocs/.

2. Add the following code at the top of the index page right after " "
$domain = $_SERVER['HTTP_HOST'];
$domain_parts = explode('.',$domain);
if (count($domain_parts) == 3 && $domain_parts[0]!= "www")
{
   // make sure a subdomain is called
   $user = $domain_parts[0];
   $loc = "http://domain.tld/somepage.ext?varname=$user";
   @header("Location:$loc");
}

- By adding this code to the index file, the subdomain will be created.
PHP - How to upload files using PHP?
PHP - Files can be uploaded in PHP by using the tag type=”file”....
PHP - What is the difference between Notify URL and Return URL?
PHP - Notify URL and Return URL is used in Paypal Payment Gateway integration.....
PHP - Describe functions STRSTR() and STRISTR.
PHP - Both the functions are used to find the first occurrence of a string...
Post your comment