0

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;

?>

1 Answer 1

3

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();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.