Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Login WHM via Remote Access Key

Discussion in 'cPanel Developers' started by Labadora, Jul 1, 2017.

  1. Labadora

    Labadora Registered

    Joined:
    Jul 1, 2017
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Egypt
    cPanel Access Level:
    Root Administrator
    hello
    I want to file ex. php whatever to access whm via Remote Access Key
    pls i don't want to any doc
    just i want to file using curl to call whm via hash code "Remote Access Key" and secure
    regards ,,
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,425
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Here's an example of how to authenticate as root to WHM using the access hash in a PHP script:

    Code:
    <?
    $whmusername = "root";
     
    # The contents of /root/.accesshash
    $hash = "accesshashhere";
     
    $query = "https://127.0.0.1:2087/json-api/listaccts?api.version=1";
     
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
     
    $header[0] = "Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$hash);
    curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
    curl_setopt($curl, CURLOPT_URL, $query);
     
    $result = curl_exec($curl);
    if ($result == false) {
        error_log("curl_exec threw error \"" . curl_error($curl) . "\" for $query");
    }
    curl_close($curl);
     
    print $result;
    ?>
    This is fully documented at:

    Guide to API Authentication - Access Hash Authentication - Software Development Kit - cPanel Documentation

    Could you review this document and let us know if you have any specific questions?

    Thanks!
     
Loading...

Share This Page