Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    1
    Thanked 0 Times in 0 Posts

    help with this cUrl script

    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


    PHP Code:
    $url "http://www.bbnsms.com/bulksms/bulksms.php"
    $ch curl_init();
    curl_setopt($chCURLOPT_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); 

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    242
    Thanks
    1
    Thanked 57 Times in 56 Posts
    From manual.
    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.

  • #3
    New Coder
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks a lot...very helpful

  • #4
    Regular Coder
    Join Date
    May 2011
    Posts
    242
    Thanks
    1
    Thanked 57 Times in 56 Posts
    You should also replace multiple calls of curl_exec with something like the following

    PHP Code:
    $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
    PHP Code:
    $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); 

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks for that, actually noticed that one and had already corrected it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •