Php 发生WHMCS错误:使用外部API时IP::1无效

Php 发生WHMCS错误:使用外部API时IP::1无效,php,api,whmcs,Php,Api,Whmcs,我正在外部API上试用GetClient密码 <?php $url = "http://localhost:81/whmcs/includes/api.php"; # URL to WHMCS API file goes here $username = "admin"; # Admin username goes here $password = "pass"; # Admin password goes here $postfields["username"] = $usernam

我正在外部API上试用GetClient密码

<?php 
$url = "http://localhost:81/whmcs/includes/api.php"; # URL to WHMCS API file goes here
$username = "admin"; # Admin username goes here
$password = "pass"; # Admin password goes here

$postfields["username"] = $username;
$postfields["password"] = md5($password);
$postfields["action"] = "GetClientPassword";
$postfields["userid"] = "1";

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$data = curl_exec($ch);
curl_close($ch);

$data = explode(";",$data);
foreach ($data AS $temp) {
    $temp = explode("=",$temp);
    $results[$temp[0]] = $temp[1];
}

if ($results["result"]=="success") {
  echo "Success<br />
<br />
";
# Result was OK!
} else {
# An error occured
echo "The following error occured: ".$results["message"];
}
?>

出错

结果=错误;消息=无效IP

我已经在常规设置->安全选项卡中添加了IP

注意:我正在本地主机(xampp)上尝试此操作


这里缺少什么?

此错误表示API访问密钥未成功添加到configuration.php文件。请参考上述第7步。$api\u access\u关键字行应该在closing?>标记之前

您还可以通过以下方式将您的IP列入白名单


设置>常规>安全>API IP访问限制

如果您在whmcs上有帐户,则必须将要访问API的IP地址列为白名单。这是whmcs团队使用的一种安全措施,以防止未经授权的用户使用自己的api。我希望这是有帮助的。谢谢

或者,可以配置访问密钥以允许绕过IP限制

它的工作原理是在WHMCS configuration.php文件中定义一个密钥/密码短语,然后将其传递到所有API调用中。要配置它,请在根WHMCS目录下的configuration.php文件中添加一行,如下所示

$api_access_key = 'secret_key_passphrase_goes_here';
引入API访问密钥后,您可以将其包括在API请求中,如下所示:

?action=xxxx&username=xxx&password=xxx&accesskey=secret_key_passphrase_goes_here
更多资讯: