Categorized | Best practices, News, PHP, Programming

Tags | ,

Using curl with PHP Tutorial

Posted on 18 February 2005 by Demian Turner

Thanks for this anonymous submission

Learn to use curl with php to query remote webservers for data. This can be done to automate form submission, process credit cards, and more. Topics covered include SSL, cookie handling, and more.

Read the full article here

Bookmark and Share

10 Comments For This Post

  1. jezzen Says:

    yeah fully recomend this curl article you are linking to. i’ve just gone beyond the basics of php programming and been learning curl to help facilitate multi server transfers. unfortunately decent curl tutorials (written in basic english anyway!) are few and far between. this article gets straight to the point. good find phpkitchen
    jezzen

  2. svitkona Says:

    thanks it helps..:D

  3. Steve Says:

    thanks!

  4. Bob Says:

    I am wondering how to do both a post and get request with curl
    in the same session.

    I need to post the user id and password to https:// url#1
    and then get the XML data from https://url#2

    I am able to perform the post successfully but get and invalid session
    response on the get request.

    // INIT CURL
    $ch = curl_init();

    // SET URL FOR THE POST FORM LOGIN
    curl_setopt($ch, CURLOPT_URL, ‘https:// url ‘);
    curl_setopt($ch, CUPROPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CUPROPT_SSL_VERIFYHOST, FALSE);

    // ENABLE HTTP POST
    curl_setopt ($ch, CURLOPT_POST, 1);

    // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD
    curl_setopt ($ch, CURLOPT_POSTFIELDS, ‘userid=fieldvalue1&password=fieldvalue2′);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);

    // EXECUTE 1st REQUEST (LOGIN)
    $postresponse = curl_exec ($ch);
    echo $postresponse

    // SET FILE TO DOWNLOAD
    curl_setopt($ch, CURLOPT_URL, ‘https:// url#2 for xml data’);

    // EXECUTE 2nd REQUEST (xml response)
    $getresponse = curl_exec ($ch);
    echo $getresponse;

    // CLOSE THE SESSION
    curl_close($ch);

    Bob
    Twenty-First Century
    website: http://www.21stcenturycompany.com
    email: tfc@21stcenturycompany.com
    phone: (888) 961-6677
    fax: (805) 964-5007

  5. kigoobe Says:

    Good article, but I am getting a wrong parameter error for curl_exec(). Writing curl_exec($ch) returns an empty page, and if curl_exec() is left empty without any parameter, it gives a wrong parameter error.

  6. Charles Says:

    for some reason i’m getting the same page back and my values for the form inputs are just placed into the form. any reason why i’d receive the same page back?

  7. Raj Says:

    How to start with Curl learning any step by step guide?

  8. Rob Rasner Wikipedia Says:

    Omg you are on the dot we are going to post to Tweets and Fb Using curl with PHP Tutorial | PHPkitchen is cool BTW our prayers to the people close by Japan hopefully your are well as well as secure too ? Salam ! Rob Rasner Wikipedia

  9. sree Says:

    Thanks a lot..Nice article

  10. Krishna paul Says:

    how to get links and details from a webpage and post them to other webpage with cURL ?

Leave a Reply

Categories

Books

Demian Turner's currently-reading book recommendations, reviews, favorite quotes, book clubs, book trivia, book lists

Facebook