私は自分のウェブサイトに自動的にログインして結果をNagiosに表示するnagiosを作成しています。Currenltyスクリプトを使用してログインできますが、PHPCurlスクリプトはログイン後に完全な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正常にログイン
この点で私を助けてください。
ありがとうFarooqHussain