1

Ok, so I haven't been able to find an answer to this question anywhere, which probably means it isn't possible. I come to the community to find out once and for all if what I want is a reality.

I would like to get php to echo out the cpanel user name so that in a config.php file, I would not have to manually change the username on a new site, or if I moved servers.

Much in the way the php could echo the current year, should it be possible to have an echo on the user name.

If I had this for example:

Cpanel path: home/userx/public_html

Than

<php echo "cpanelusername" ?>

I am aware there is more than echo username, however, my demonstration is only for the purpose of describing what I want.

Is there a way to do such a thing?

Matthew Davis
  • 117
  • 1
  • 10

1 Answers1

0

You can use the cPanel UAPI for this:

$cpanel = new CPANEL();

$users = $cpanel->uapi('Ftp', 'list_ftp', [
    'include_acct_types' => 'main'
]);

if ($users && isset($users[0]['type']) && $users[0]['type'] == 'main') {
    $user = $users[0]['user'];

    // The cPanel username
    var_dump($user);
}

By setting include_acct_types to main you will only get the main FTP account, which holds the main cPanel username. The extra checks to make sure $users[0]['type'] is set and is the main account might be an overkill, but you never know.

Source: https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Ftp%3A%3Alist_ftp

SomeCode
  • 179
  • 2
  • 15