Automatic Subdomain Creation?

  • petgraveyard
  • Novice
  • Novice
  • User avatar
  • Posts: 24
  • Loc: Philadelphia, Pennsylvania, United States

Post 3+ Months Ago

Alright, so you know how some websites that make user profiles give you a subdomain automatically (username.example.com)? I'm on a paid host using CPanel 11 and I've got like zero experience with Apache, only PHP and such. Can you tell me how to dynamically create subdomains when users register for accounts in an account system (using PHP or some sort of Cron-like thing)?

I tried searching the forum, but to no avail. Any help is GREATLY appreciated!
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ninja.
  • Born
  • Born
  • User avatar
  • Posts: 3

Post 3+ Months Ago

Hi man i from BiH can you add me miMo.Tarik@hotmail.com
I need to ask you something please
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6247
  • Loc: Seattle, WA
  • Nebulous
  • Beginner
  • Beginner
  • Nebulous
  • Posts: 59
  • Loc: Hampshire, UK

Post 3+ Months Ago

It is extremely easy to parse the information to cPanel to get that to create the sub domain.

cPanel allows the use to GET variables in their applications, so it is very easy to send a URL using fopen()/ cURL

PHP Code: [ Select ]
$addr = "http://$domain_name:2082/frontend/$skin/mail/doaddpop.html";
$string_values = "email=$_POST[email]&domain=$domain_name&password=$_POST[confirm]&quota=$email_quota";
  1. $addr = "http://$domain_name:2082/frontend/$skin/mail/doaddpop.html";
  2. $string_values = "email=$_POST[email]&domain=$domain_name&password=$_POST[confirm]&quota=$email_quota";


Thats the URL im currently using for my cPanel email creator script, so if you find the URL to the sub domain page, and look at the name of all of the form inputs you should be able to do the same.

Regards.
  • cPanelDavidG
  • Born
  • Born
  • cPanelDavidG
  • Posts: 2
  • Loc: Houston, TX

Post 3+ Months Ago

petgraveyard wrote:
Alright, so you know how some websites that make user profiles give you a subdomain automatically (username.example.com)? I'm on a paid host using CPanel 11 and I've got like zero experience with Apache, only PHP and such. Can you tell me how to dynamically create subdomains when users register for accounts in an account system (using PHP or some sort of Cron-like thing)?

I tried searching the forum, but to no avail. Any help is GREATLY appreciated!


The easiest and most reliable way of doing this would be to use the XML API over port 2082 (port 2083 if using SSL).

The actual function for creating a subdomain in cPanel is an API1 function:

Code: [ Select ]
<cpanel SubDomain="addsubdomain(domain,rootdomain,0,0,dir)">


domain = subdomain to create

rootdomain = the domain under which to create the subdomain

dir = path beginning at the user's home directory where pages for this subdomain will be stored

So if I wanted to create the subdomain something.example.com that points to ~/subdomains/something, I would have:

Code: [ Select ]
<cpanel SubDomain="addsubdomain(something,example.com,0,0,subdomains/something)">


As for translating this all into PHP, we have a PHP 5 class in the developer section of the cPanel Community Forums available for download to handle all of that for you.
  • effim
  • Beginner
  • Beginner
  • User avatar
  • Posts: 35
  • Loc: Austin, TX

Post 3+ Months Ago

cPanelDavidG wrote:
...


You might want to refrain from digging up very old threads, opting instead to provide support for more recent ones. Sometimes it's helpful for visitors arriving from search engines, but most of the time it just confuses people.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

effim wrote:
cPanelDavidG wrote:
...


You might want to refrain from digging up very old threads, opting instead to provide support for more recent ones. Sometimes it's helpful for visitors arriving from search engines, but most of the time it just confuses people.

Not really... that helped me a ton since I was thinking of doing something similar.

Unanswered posts are like ghost towns... towns that failed.
  • dark_lord
  • Graduate
  • Graduate
  • User avatar
  • Posts: 162
  • Loc: India-Kolkata

Post 3+ Months Ago

if you have limitation on sub-domain creation

you can apply this to get unlimited sub-domains

go to sub-domain area and then make *.something.com as a subdomain from cpanel.

then you make a permanent redirect from *.something.com to something.com

it will virtually redirect all sub-domain(even if a sub-domain doesn't exists) to your main account i.e. something.com

In this way you can in fact create unlimited sub-domains even if you don't have the permission to do so.

This is the most easiest but not the worthiest, because then everything depends on your main page coding.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 151 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.