How to create error reporting for this script below to make sure its working and is there anything wrong with it
<?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;
?>
curl_exec()
returns FALSE
on failure. Check for it's success before echoing your $result
. On failure, call curl_error()
to see the most recent error message returned.
$result = curl_exec ($ch);
if ($result) {
// Success.
echo $result;
}
else {
// something went wrong.
echo curl_error($ch);
}
curl_close($ch);
exit();
精彩评论