我正在尝试实现显示cpanel的awstats页面。我想自动登录到cpanel,然后显示传递域的awstats。我使用了以下代码,但似乎登录页面并没有显示awstats页面
$cp_user = "<username>";
$cp_pwd = "<password>";
$url = "https://xxxx:2083/login";
$cookies = "cookies.txt";
$ch=curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); // Save cookies to
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$cp_user&pass=$cp_pwd");
curl_setopt($ch, CURLOPT_TIMEOUT, 100020);
$f = curl_exec($ch);
$h = curl_getinfo($ch);
curl_close($ch);
if ($f == true and strpos($h['url'],"cpsess"))
{
// Get the cpsess part of the url
$pattern="/.*?(\/cpsess.*?)\/.*?/is";
$preg_res=preg_match($pattern,$h['url'],$cpsess);
}
$token= $cpsess[1];
header('Locations: https://xxxx:2083'.$token.'/awstats.pl?config=<domain>&ssl=&lang=en');
这有什么问题吗?
答案 0 :(得分:0)
我知道这是一个老问题,但我想我会抛出一个答案,因为没有其他人做出回应。也许它会帮助别人尝试这个。
您无法正常工作的原因是因为cPanel验证了用户的IP地址。您的cURL脚本通过其IP保存在您的服务器上,尝试登录的用户拥有自己的IP地址。
查看cPanel(x3)登录表单,甚至没有表单字段来提交您的IP地址,因此仅在服务器端检索它以防止欺骗。
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, "user=myuser&pass=mypass");
$result = curl_exec($curl);
$header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $header_size);
$body = substr($result, $header_size);
curl_close($curl);
$header = str_replace("\r", '', $header);
$header = explode("\n", $header);
foreach ($header as $h) {
header ($h);
}
$parts = explode( 'URL=', $result);
$session_parts = explode( '/frontend/', $parts[1]);
$token = $session_parts[0];
header('Location: http://ss.com:2082'.$token.'/awstats.pl?config=ss.com&ssl=&lang=pt');