Web Analytics Made Easy -
StatCounter help with this cUrl script - CodingForum

Announcement

Collapse
No announcement yet.

help with this cUrl script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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
    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.

    Comment


    • #3
      Thanks a lot...very helpful

      Comment


      • #4
        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); 

        Comment


        • #5
          thanks for that, actually noticed that one and had already corrected it.

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎