0

我正在创建一个 nagios,它将自动登录到我的网站并在 Nagios 中显示结果。Currenlty 我可以使用脚本登录,但我的 PHP Curl 脚本在通过 curl 登录后返回完整的 HTML 代码。

这是我的脚本。

<?php
$id = "username";
$pw = "password";
$postfields = "userName=farooq&password=hussaind";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1); // Get the header
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Allow redirection
curl_setopt($ch, CURLOPT_COOKIEJAR, "/tmp/cookie");
curl_setopt($ch, CURLOPT_URL,"http://abc.com/signin.htm");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) ");
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");
curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
# echo $statusCode;
if ($statusCode >= 200) {
echo 'OK - Status Code = '. $statusCode . '. Successfully Login' ;
exit (0);
}
else if ($statusCode >= 400){
echo 'CRITICAL - Status Code = '. $statusCode . '. Unable to loging. Please check ';
exit(2);
}
else {
echo 'UNKOWN - Status Code = '. $statusCode . '. Unable to loging. Please check ';
exit(1);
}
curl_close($ch);
?>

我只想打印没有任何 HTML 废话的简单消息。喜欢

OK - 状态码 = 200 成功登录

请在这方面帮助我。

谢谢法鲁克侯赛因

4

1 回答 1

1

设置CURLOPT_RETURNTRANSFERtrue

http://www.php.net/manual/en/function.curl-setopt.php

于 2012-09-03T22:06:36.717 回答