I am trying to log into a forum and send a message to an user but no effect.
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, ‘http://exemple.com/login.php’);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, ‘username=USER&password=1234567′);
curl_setopt ($ch, CURLOPT_COOKIEJAR, ‘cookie.txt’);
$login = curl_exec ($ch);
curl_setopt ($ch, CURLOPT_URL, ‘http://exemple.com/privatemessage.php?receiver=7067′);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, ‘msg=Test’);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$post = curl_exec ($ch);
curl_close ($ch);
print_r($login) . “\n”;
?>What is wrong ? It’s first time using cURL ..
Thanks for your time…
Here is the HTML part
…………………………………..
Try:
$login = curl_exec ($ch);
if ($login === FALSE) {
die(curl_error($ch));
}and similar for the second curl run. You should never assume that a call to an external service succeeded. die() is useful to kill things in development. For product you can replace it with a more comprehensive error handler.