...

View Full Version : help with this cUrl script



jerry4all
08-25-2011, 07:58 AM
Got my sms script working, thanks the people here.. but for this little problem.

it prints the contents of $response without adding the print command and the ifelse function constantly returns the response of the first condition. Any help will be very useful
Here's the cUrl section of the script



$url = "http://www.bbnsms.com/bulksms/bulksms.php";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$request);
if ( "1801" == curl_exec($ch))
echo "Message sent successfully";
elseif (curl_exec($ch) == "1802")
echo "Invalid username";
elseif (curl_exec($ch) == "1803")
echo "Invalid password";
curl_close($ch);

gvre
08-25-2011, 11:10 AM
From manual (http://php.net/manual/en/function.curl-exec.php).

Returns TRUE on success or FALSE on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, FALSE on failure.
So, you must set the CURLOPT_RETURNTRANSFER option.

jerry4all
08-25-2011, 01:55 PM
Thanks a lot...very helpful:thumbsup:

gvre
08-25-2011, 03:35 PM
You should also replace multiple calls of curl_exec with something like the following


$response = curl_exec($ch);
if ($response == "1801")
echo "Message sent successfully";
else if ($response == "1802")
echo "Invalid username";
else if ($response == "1803")
echo "Invalid password";
curl_close($ch);

or

$response = curl_exec($ch);
switch($response)
{
case "1801":
echo "Message sent successfully";
break;
case "1802":
echo "Invalid username";
break;
case "1803":
echo "Invalid password";
break;
default:
// ??
}
curl_close($ch);

jerry4all
08-25-2011, 04:16 PM
thanks for that, actually noticed that one and had already corrected it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum