1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP cURL tutorial

Discussion in 'PHP & Perl' started by cbnoob, Dec 10, 2011.

Tags:
  1. cbnoob

    cbnoob Senior Member

    Joined:
    Sep 27, 2010
    Messages:
    967
    Likes Received:
    455
    Hey PHP guys,

    I'm learning cURL in php now but there was not many good tutorial or book on this. I've just grabbed a book, written by phptrack. It's the only book available about this topic I can find. I think some of you guys may finding the same stuff. Hope it helps somehow.

    Download
    Code:
    http://www.mediafire.com/?dj961s32t7gahaq
    VT

    Code:
    http://www.virustotal.com/file-scan/report.html?id=66e5305cb4cec10f8d08a1cc72597eb90f3af9b0d5ab98c883df5165903a6575-1323538361
    File name:
    PHP cURL.zip
    Submission date:
    2011-12-10 17:32:41 (UTC)
    Current status:
    finished
    Result:
    1/ 42 (2.4%)
     
    • Thanks Thanks x 12
  2. ``Yousef

    ``Yousef Power Member

    Joined:
    Oct 16, 2009
    Messages:
    534
    Likes Received:
    286
    Location:
    Cooking up the medicine.
    Home Page:
    Being a PHP developer who often uses cURL, it's a pretty good read, especially for someone who's just starting out with PHP/cURL, and needs a guide to run them through step-by-step cURL usage, from retrieving a basic page to sending data via the the HTTP POST method to adding additional cURL options, such as setting a user agent or referrer.
     
  3. WizGizmo

    WizGizmo Super Moderator Staff Member Premium Member

    Joined:
    Mar 28, 2008
    Messages:
    3,833
    Likes Received:
    55,431
    Thread moved to the PHP/PERL section.

    "Wiz"
     
    • Thanks Thanks x 1
  4. kazhkaz

    kazhkaz Jr. VIP Jr. VIP Premium Member

    Joined:
    Aug 19, 2010
    Messages:
    1,238
    Likes Received:
    369
    does it write how to receive captcha and send answer back to page?
     
  5. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    Every captcha is different. But even recaptcha is easy once you get the hang of it.
    (You just have to parse the javascript, and follow what your browser would do).
     
    • Thanks Thanks x 1
  6. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    For newbies to CURL:
    One thing the PDF fails to mention is detecting CURL errors. More often than not, if you do not handle CURL errors you can be sitting there scratching your head for a long time wondering why the hell no content is being returned. A simple way to detect CURL erros is by adding an error detection to the CURL handler:
    $err = curl_errno($ch);

    This will return a number, you can store common errors in your code to return the error or look them up here:
    http://curl.haxx.se/libcurl/c/libcurl-errors.html

    This can save a lot of time and hassle when using CURL with sites like Twitter who return a lot of Not Allowed requests when you are posting content using an incorrect content-type.
     
    • Thanks Thanks x 3
  7. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    575
    Likes Received:
    212
    This is great. Im' planning to do http post request.
    What is the difference between using cUrl and native PHP functions?
     
  8. mark0v

    mark0v Junior Member

    Joined:
    May 6, 2010
    Messages:
    114
    Likes Received:
    20
    you can do a lot with curl that you wouldn't otherwise be able to do (to my knowledge)
    i.e. fake a referrer, user agent, multi threading, etc.
     
    • Thanks Thanks x 1
  9. .:Raymond:.

    .:Raymond:. Junior Member

    Joined:
    Dec 13, 2011
    Messages:
    105
    Likes Received:
    94
    Occupation:
    SEO
    Location:
    Canada
    Home Page:
    Thanks for the download man :)

    Been wanting to learn curl for a while
     
  10. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    575
    Likes Received:
    212
    so, it's more sutable for blackhat stuff,

    and what about PECL, it too has similar things?
     
  11. zmutclik

    zmutclik Newbie

    Joined:
    Dec 13, 2011
    Messages:
    9
    Likes Received:
    0
    Thanks, but I want to ask, curl looping application capable of how long the process in memory
    :D
     
  12. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Forever:
    Code:
    ini_set("max_execution_time","0");
    ignore_user_abort(true);
    set_time_limit(0);
    
     
  13. boudewijn

    boudewijn Newbie

    Joined:
    May 27, 2011
    Messages:
    22
    Likes Received:
    5
    Great share OP!
    I was looking for a tutorial on cURL and big G brought me here :D
     
  14. zbigbz

    zbigbz Newbie

    Joined:
    Apr 30, 2011
    Messages:
    38
    Likes Received:
    16
    Boy is this timley! I've been doing some cURL with proxy's, referrers, cookies and user agents and following examples in the cURL documentation that say's turn headers ON, no turn Headers OFF, same with CURLOPT_FOLLOWLOCATION , CURLOPT_AUTOREFERER , CURLOPT_RETURNTRANSFER , CURLOPT_FRESH_CONNECT, CURLOPT_FORBID_REUSE - my head is spinning!

    My code works - much of the time, but big G catches on to me pretty quickly and gives me a CAPTCHA page with the message - Our systems have detected unusual traffic from your computer network. This page checks to see if it's really you sending the requests and not a robot. - Of course the code is a bot, but I was expecting cURL to help.

    A quick look at the pdf - especially the section on debugging looks especially promising.

    Of course, if anyone has any pointers to examples that really work I'd welcome them.
     
    Last edited: Dec 14, 2011
  15. B.O.S.S

    B.O.S.S Power Member

    Joined:
    Dec 1, 2011
    Messages:
    539
    Likes Received:
    122
    Occupation:
    Social Media Marketeer
    Location:
    19.16.1:69
    Home Page:
    I have been looking for a tut. Thxx
     
  16. fathobbitsss

    fathobbitsss Junior Member

    Joined:
    Jun 17, 2011
    Messages:
    106
    Likes Received:
    21
    Cheers for the share mate,

    took one look at curl before and it scared me with all the different functions, and lack of indepth online tutorial.

    Shall take a flick through
     
  17. Tensegrity

    Tensegrity Jr. VIP Jr. VIP Premium Member

    Joined:
    Apr 22, 2009
    Messages:
    1,823
    Likes Received:
    968
    I'm no noob to cURL, but there is certainly a lack of *useful* cURL information out there for bot makers. Definitely recommend checking this one out :D
     
  18. hypefrenzy

    hypefrenzy Junior Member

    Joined:
    Dec 12, 2011
    Messages:
    170
    Likes Received:
    19
    php simply grabs website content to be analyzed. curl also does this however it can also post forms, log into accounts, and help disguise your requests to help stay off the radar

     
  19. blackhatchampion

    blackhatchampion Senior Member

    Joined:
    Dec 29, 2010
    Messages:
    1,068
    Likes Received:
    550
    Location:
    Earth
    good share mate. thanks
     
  20. cbnoob

    cbnoob Senior Member

    Joined:
    Sep 27, 2010
    Messages:
    967
    Likes Received:
    455
    it seems the link is down, here it is again
    Code:
    http://www.mediafire.com/?5egs60sf1akswyy
     
    • Thanks Thanks x 3