Creating Subdomains using PHP
Hi,
I have created a PHP script that automatically creates a Subdomain in cPanel. My original plan was for the script to run without any input from the user running the script in question to create a Subdomain.
However, the problem I have is that when the script runs, the user is redirected to a page that says: HTTP error 401 - Invalid Security Token and requires the user to then login using a cPanel Username and Password.
How can I get round this?
Here is what I echo out BEFORE being redirected to the cPanel Login page.
HTTP/1.1 301 Moved Server: cpsrvd Connection: close Content-length: 227 Location:
-
Hello, Documentation on API authentication is available at: Guide to API Authentication - Software Development Kit - cPanel Documentation Could you provide us with the contents of the PHP script you are using to create the subdomain? Thank you. 0 -
Hello, the PHP is below: $cpanel_user = 'REMOVED'; $cpanel_pass = 'REMOVED'; $cpanel_skin = 'paper_lantern'; $cpanel_host = 'REMOVED'; $dir = 'public_html/'; $sock = fsockopen($cpanel_host, 2082); if(!$sock) { print('Socket error'); exit(); } $pass = base64_encode("$cpanel_user:$cpanel_pass"); $in = "GET /frontend/$cpanel_skin/subdomain/doadddomain.html?rootdomain=$cpanel_host&domain=$subdomain&dir=$dir\r\n"; $in .= "HTTP/1.0\r\n"; $in .= "Host:$cpanel_host\r\n"; $in .= "Authorization: Basic $pass\r\n"; $in .= "\r\n"; fputs($sock, $in); while (!feof($sock)) { $result .= fgets ($sock, 128); } echo $result;0 -
Hello, The example you provided does not appear to authenticate properly due to lack of a session ID. You should consider using the following cPanel API 2 function and PHP client class to develop the PHP script: cPanel API 2 Functions - SubDomain::addsubdomain - Software Development Kit - cPanel Documentation GitHub - CpanelInc/xmlapi-php: A PHP Class for Interacting with cPanel's XML-API Thank you. 0 -
Hello, Could you please assist me to solve the issue I have a website. Hosted on linux shared need to create automatic subdomains on user registration based on username entered in registration form The hosting allows unlimited subdomains I would like someone to assist me 0 -
@pradipkp - just as the earlier posters in this thread, you would need to create a custom solution using the cPanel API that integrates with your server and website. There isn't a ready-made code example that will perform this work for you. 0
Please sign in to leave a comment.
Comments
5 comments