GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  PHP
Go To First  |  Previous Question  |  Next Question 
 PHP  |  Question 52 of 62    Print  
How do you create subdomains using PHP?
How will you create sub domains without manually creating it from Control Panel? Sub Domains must me created by using PHP script for a membership website. Answer with a sample script.


  
Total Answers and Comments: 4 Last Update: September 06, 2008     Asked by: thunderman 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
February 08, 2008 04:41:11   #1  
ninethsense Member Since: May 2007   Contribution: 6    

RE: How do you create subdomains using PHP?

* Create the appropriate web root directory, for example /home/sites/username/web , and any subdirectories you wish 
* Edit httpd.conf -  add a new virtual host section 
* Restart httpd


In a normal Linux server setup, php/Apache does not have the necessary permissions to do all this.


 
Is this answer useful? Yes | No
March 14, 2008 00:52:39   #2  
dipeshpatel Member Since: January 2008   Contribution: 2    

RE: How do you create subdomains using PHP?
Hello,

You can crate a virtual domain by using .htaccess file and you need to set some little things in control panel.

by using .htaccess file you can crate like as a under mention example.


http://www.domain.com/?a=user --> http://user.domain.com/

 
Is this answer useful? Yes | No
July 28, 2008 04:25:28   #3  
akhilesh1010 Member Since: July 2008   Contribution: 4    

RE: How do you create subdomains using PHP?
use this script to add new subdoamin in your cpanel account

subdomainform.php


<html>
<head>
<title>create a subdomain</title>
</head>
<body>
<form name="form1" method="post" action="addsubdomain.php">
<h1>create Sub Domains</h1>
Sub Domain Name : <input type="text" name="subdomain"><br />
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>


==============================

addsubdomain.php
=============================

<?php

ini_set('display_errors', 1);

$host = "domainname.com"; // your domain name without the www
$port = 2082;
$path = "/frontend/x/subdomain/doadddomain.html?domain=".$_POST['subdomain']."&rootdomain=".$host; //or .dll, etc. for authnet, etc.

// these lines are changed
$cpaneluser = "username";
$cpanelpass = "pass";
$authstr = "$cpaneluser:$cpanelpass";
//****************************

// Setup the Auth String
$pass = base64_encode($authstr);

$fp = fsockopen($host, $port, $errno, $errstr, $timeout = 30);

if(!$fp){
//error tell us
echo "$errstr ($errno)n";

}else{

//send the server request

fputs($fp, "POST $path HTTP/1.1rn");
fputs($fp, "Host: $hostrn");
fputs($fp, "Authorization: Basic $pass rn");
fputs($fp, "Content-type: application/x-www-form-urlencodedrn");
fputs($fp, "Content-length: ".strlen($poststring)."rn");
fputs($fp, "Connection: closernrn");
fputs($fp, $poststring . "rnrn");

//*************************************
// Remove this to stop it from displaying the output fron the CPanel
//*************************************
//loop through the response from the server
/*
while(!feof($fp)) {
echo fgets($fp, 4096);
}

*/
while(!feof($fp)) { fgets($fp, 4096); }
//close fp - we are done with it
fclose($fp);
}



 
Is this answer useful? Yes | No
September 05, 2008 23:49:34   #4  
surendra246 Member Since: September 2008   Contribution: 1    

RE: How do you create subdomains using PHP?
  1. In you main httpd.conf, add the following line at the bottom:

    Include /path/to/subdomains.conf

file name subdomains.conf


@mkdir ( "/path/to/subdirectory/".$name );

  1.     $vhost = "
  2.     ServerAdmin yourname@yourserver.com
  3.     DocumentRoot /path/to/subdirectory/".$name."
  4.     ServerName ".$name.".yourserver.com
  5.     ErrorLog /path/to/logs/".$name."_error_log
  6. ";
  7.     $fo = fopen ( "/path/to/subdomains.conf", "a" );
  8.     $fw = fwrite ( $fo, $vhost );
  9.     fclose ( $fo );

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape