
Originally Posted by
xMichio
Hey,
Guys i want to run a free small community short URL service, for this i need a php, curl whatevre type script to automaticaly add subdomains via cpanel and then set the forwarder to go to the website requested. I have looked around but seems most samples dont work or i cant get them to work. I am the owner of my own server so i can install more scripts if needed to make this work.
Regards,
Michio
Here is the code that I use to add sudmains through php:
PHP Code:
<?
include ('../cpinfo.php');
$authstr = "$username:$password";
$pass = base64_encode($authstr);
//Here we open a socket to the cpanel
$socket2 = fsockopen("www.mydomain.com",2082);
if(!$socket2)
{
print('Socket error');
echo "<BR>There was an error while setting up the account. Please let support@mydomain.com know the above error";
exit();
}
//Next, we add a subdomain with $ustring
$indom = "GET /frontend/xlagoon/subdomain/doadddomain.html?domain=$web_username&rootdomain=mydomain.com\r\n HTTP/1.0\r\nHost:$udomain\r\nAuthorization: Basic $pass\r\n\r\n";
fputs($socket2,$indom);
while (!feof($socket2)) {
fgets ($socket2,128);
}
fclose($socket2);
?>
And of course cpinfo.php contains my cpanel username and password, which is located above my public_html directory for security.
With this particular code it just gives you a blank screen...at the end you could just add a forwarder to the page you want.