Hi,
I am trying to write a php script which when executed from the browser, will redirect and login to the WHM and am looking forward to some help regarding the same.
I have read through a similar post (old, though).. http://forums.cpanel.net/f42/help-whm-login-script-php-161349.html
My scenario:
Trying using curl to execute json-api, like applist works:
But trying to get the same idea executed via php header() is failing for me:
Using the header() stuff, even json calls fail, say if I change to:
.. and when I load this php script, it redirects to ../applist with the following error:
I am sure the remotekey is corret, as curl api calls (first code block) function fine for me.
I played around with the code from http://forums.cpanel.net/f42/help-whm-login-script-php-161349.html but without success. I always end up with the WHM login screen, or its login prompt.
What to do? Help..!!
I am trying to write a php script which when executed from the browser, will redirect and login to the WHM and am looking forward to some help regarding the same.
I have read through a similar post (old, though).. http://forums.cpanel.net/f42/help-whm-login-script-php-161349.html
My scenario:
Trying using curl to execute json-api, like applist works:
PHP:
$api = "applist";
$query = "https://$ip:2087/json-api/$api";
$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)'","",$remotekey); // remotekey stored in db as TEXT
curl_setopt($curl,CURLOPT_HTTPHEADER,$header);
curl_setopt($curl, CURLOPT_URL, $query);
$result = curl_exec($curl);
curl_close($curl);
if ($result == false) {
return FALSE; // error
}
return json_decode($result, true);
PHP:
$srv_info = array(
"ip" => $row->s_ip,
"username" => $row->user_name,
"remotekey" => $row->remote_key
);
$ip = $srv_info["ip"];
$whmusername = $srv_info["username"];
$remotekey = $srv_info["remotekey"];
header("Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$remotekey));
header("Location: http://" . $ip . ":2086/");
// Also tried:
// header("Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$remotekey) . "\r\n");
// header("Location: https://" . $ip . ":2087/");
PHP:
header("Authorization: WHM $whmusername:" . preg_replace("'(\r|\n)'","",$remotekey));
header("Location: http://" . $ip . ":2086/json-api/applist");
Code:
{"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}}
I played around with the code from http://forums.cpanel.net/f42/help-whm-login-script-php-161349.html but without success. I always end up with the WHM login screen, or its login prompt.
What to do? Help..!!
Last edited: