Bismillah..,
mudah-mudahan nggak repost..kalau thread ini tidak bermanfaat, silahkan momod mengahapusnya.
berawal dari banyaknya client yang beli script PHP AGC amazon (phpzonkill) meminta cara untuk membuat subdomain tanpa harus ribet via cpanel.
maka ane inisiatif buat aja threadnya disini, sekalian di share (tadinya mau di jual $2 dengan sedikit tambahan session untuk membatasi akses :D)
Berikut script php untuk membuat sub domain :
<?php
define
(
'CPANELUSER'
,
'user'
);
define
(
'CPANELPASS'
,
'pass'
);
//define('INPUT_FILE','domains.txt');
define
(
'CPANEL_SKIN'
,
'x'
);
define
(
'DOMAIN'
,
''
);
function
getVar
(
$name
,
$def
=
''
) {
if (isset(
$_REQUEST
[
$name
]) && (
$_REQUEST
[
$name
] !=
''
))
return
$_REQUEST
[
$name
];
else
return
$def
;
}
/*
$cpaneluser=getVar('cpaneluser', CPANELUSER);
$cpanelpass=getVar('cpanelpass', CPANELPASS);
$cpanel_skin = getVar('cpanelskin', CPANEL_SKIN);
*/
$cpaneluser
=
"logincpanelanda"
;
$cpanelpass
=
"passwordcpanelanda"
;
$cpanel_skin
=
"x3"
;
if (isset(
$_REQUEST
[
"subdomain"
])) {
// get parameters passed via URL or form, emulate string from file
$doms
= array(
getVar
(
'domain'
,
DOMAIN
) .
";"
.
$_REQUEST
[
"subdomain"
]);
if (
getVar
(
'domain'
,
DOMAIN
) ==
''
) die(
"You must specify domain name"
);
}
else {
// open file with domains list
$doms
= @
file
(
INPUT_FILE
);
if (!
$doms
) {
// file does not exist, show input form
echo
"
<form method='post'>
Subdomain:<input name='subdomain'><br>
Domain:<input name='domain'><br>
<!--cPanel User:<input name='cpaneluser'><br>
cPanel Password:<input name='cpanelpass'><br>
cPanel Skin:<input name='cpanelskin'><br>-->
<input type='submit' value='Create Subdomain' style='border:1px solid black'>
</form>"
;
die();
}
}
// create subdomain
function
subd
(
$host
,
$port
,
$ownername
,
$passw
,
$request
) {
$sock
=
fsockopen
(
'localhost'
,
2082
);
if(!
$sock
) {
print(
'Socket error'
);
exit();
}
$authstr
=
"
$ownername
:
$passw
"
;
$pass
=
base64_encode
(
$authstr
);
$in
=
"GET
$request
\r\n"
;
$in
.=
"HTTP/1.0\r\n"
;
$in
.=
"Host:
$host
\r\n"
;
$in
.=
"Authorization: Basic
$pass
\r\n"
;
$in
.=
"\r\n"
;
fputs
(
$sock
,
$in
);
while (!
feof
(
$sock
)) {
$result
.=
fgets
(
$sock
,
128
);
}
fclose
(
$sock
);
return
$result
;
}
foreach(
$doms
as
$dom
) {
$lines
=
explode
(
';'
,
$dom
);
if (
count
(
$lines
) ==
2
) {
// domain and subdomain passed
$domain
=
trim
(
$lines
[
0
]);
$subd
=
trim
(
$lines
[
1
]);
}
else {
// only subdomain passed
$domain
=
getVar
(
'domain'
,
DOMAIN
);
$subd
=
trim
(
$lines
[
0
]);
}
// http://[domainhere]:2082/frontend/x/subdomain/doadddomain.html?domain=[subdomain here]&rootdomain=[domain here]
$request
=
"/frontend/
$cpanel_skin
/subdomain/doadddomain.html?rootdomain=
$domain
&domain=
$subd
"
;
$result
=
subd
(
'localhost'
,
2082
,
$cpaneluser
,
$cpanelpass
,
$request
);
$show
=
strip_tags
(
$result
);
//echo $show;
}
?>
Cara penggunaan :
1. edit variable dibawah dengan info login cpanel anda :
$cpaneluser
=
"logincpanelanda"
;
$cpanelpass
=
"passwordcpanelanda"
;
2. simpan file diatas dengan nama bebas saja (misal : subdomen.php)
3. jalankan file dari browser, misal : domain.com/subdomain.php
4. - isi field Subdomain dengan nama subdomain yg diinginkan (misal : test)
- isi field Domain dengan nama domain yg ada di hosting cpanel agan, support addon domain
sedikit saran, sebaiknya script diatas disempurnakan dengan memberikan session login
Mudah2an bermanfaat