Categories
Related Products
Follow @expbuilder
Subscribe to to get latest news
|
| Visit ExpBuilder group |
How to Create Subdomains and Ftp Accounts with PHP Develop by connecting to Cpanel tutorial
Hello every body, Today we will talk about how to create subdomains and ftp account with php by connecting to Cpanel
Let’s get started:
1- Create three php files as the following:
- cpanel.Config.php
- cpanel.functions.php
- cpanel.connection.php
$cpanel['sitename'] = 'yoursitename.com'; //Your domain name
$cpanel['port'] = '2082'; // Cpanel port
$cpanel['username'] = 'username'; //your cpanel username
$cpanel['password'] = '123456'; //your cpanel password
$cpanel['skin'] = 'x3'; //your cpanel skin name - x3 is always default
?>
This file is the configuration file , to set the Cpanel connection information
3- open cpanel.functions.php and type the following:
function opencpanel($url)
{
global $cpanel; // get cpanel variable from config file
$page = @file("http://".$cpanel['username'].":".$cpanel['password']."@www.".$cpanel['sitename'].":".$cpanel['port']."/frontend/".$cpanel['skin']."/".$url); // send username and password connection with the url path
if($page) // if it done then return result
{
return implode("", $page);
}
else // else return false
{
return false;
}
}
function create_ftp_account($username, $password, $ftp_quota)
{
$data = opencpanel("ftp/doaddftp.html?login=".$username."&password=".$password."&password2=".$password."&homedir=public_html/files/".$username.""a=".$ftp_quota); send information data to create the ftp to page (ftp/doaddftp.html) to create the FTP accountif($data) // if return result
{
//get information
$dstatu = explode('class="status">', $data);
$dstatu2 = explode("", $dstatu[1]);
if($dstatu2[0] == "Account created successfully.") //if this line =Account created successfully. then return it True{
return true;
}
else
{
return false;
}
}
}
function create_subdomain($username)
{
$data = opencpanel("subdomain/doadddomain.html?domain=".$username."&rootdomain=".$cpanel['sitename']."&dir=public_html/");
if($data)
{
$dstatu = explode('class="status">', $data);
$dstatu2 = explode("\n", $dstatu[1]);
if($dstatu2[0] == $username.".".$cpanel['sitename']."
{
return true;
}
else
{
return false;
}
}
}
?>
Now what is these functions ? - - 4- Now open cpanel.connection.php file and the following : //include files include "cpanel.Config.php"; include "cpanel.functions.php"; //now if user want to create subdomain then it will appear here the $_POST['subdomainname'] here: if($_POST['subdomainname']) { if( { echo "Your subdomain ".$_POST['subdomainname']." Created successfully ! } else { echo "Can't create the subdomain ".$_POST['subdomainname']." ! } } //also if he want to create ftp account if($_POST[' { if( { echo "Your FTP ".$_POST[' } else { echo "Can't create the FTP ".$_POST[' } } //here is the HTML page ?>- opencpanel(here is the link of cpanel page) ->> this function for send data to cpanel and return the result by function file() with creating the connection (send username and password) ... create_subdomain (the subdomain name as you want)->> for creating the subdomaincreate_ftp_account ->> to create the ftp accounts$_POST['subdomainname']$create = create_subdomain();//create the sub domain$create)
"; // if return true then say created successfully
"; // if not then say errorclient_user_name'])$create = $_POST['create_ftp_account(client_user_name']$_POST[', password'], "100");$create)']." Created successfully !client_user_name
"; // if return true then say created successfully']." !client_user_name
"; // if not then say error
Now it's done,
you can test script, run: www.yoursite.com/cpanel.connection.php
Have fun
to download the tutorial from Attachment
Good luck


