如何为此脚本创建错误报告,以确保其正常工作 并且它有什么问题
<?php
$username="username here";
$password="password here";
$url="url here";
$cookie="cookie.txt";
$postdata = $username . $password . $url;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, true);
$result = curl_exec ($ch);
curl_close($ch);
echo $result;
exit;
?>
答案 0 :(得分:3)
curl_exec()
失败时返回FALSE
。在回复$result
之前检查它是否成功。如果失败,请致电curl_error()
以查看最新的错误消息。
$result = curl_exec ($ch);
if ($result) {
// Success.
echo $result;
}
else {
// something went wrong.
echo curl_error($ch);
}
curl_close($ch);
exit();