Dan Ashbridge

Registered
Mar 1, 2017
2
0
1
Shropshire
cPanel Access Level
Root Administrator
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: https://REMOVED IP ADDRESS:2083/frontend/paper_lantern/subdomain/doadddomain.html?rootdomain=REMOVED IP ADDRESS&domain=test&dir=public_html/ Content-type: text/html; charset="utf-8" Cache-Control: no-cache, no-store, must-revalidate, private Pragma: no-cache

I hope that someone can help resolve this issue.

Thanks.
 

Dan Ashbridge

Registered
Mar 1, 2017
2
0
1
Shropshire
cPanel Access Level
Root Administrator
Hello, the PHP is below:
Code:
$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;
 
Last edited by a moderator:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,216
463

pradipkp

Registered
Aug 10, 2021
1
0
1
Mumbai
cPanel Access Level
Website Owner
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