Sending HTTP POST with php cURL

advertisement logo

 

As promised previously, I’m going to show you how to send HTTP POST request using php cURL extension.

The target form

Let’s say you have a html form like this :

wtf

And this is the source code of the html file :


You can see that the form will submit the query using HTTP POST to “target.php”. Now let’s say you want to write a php script (bot.php) that will automatically send the query bypassing the html form, this is one way to do it (with php libcurl extension)

< ?php
//bot.php
$url = "http://localhost/wtf/target.php";
$ch = curl_init();

// set the target url
curl_setopt($ch, CURLOPT_URL,$url);

// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 1);

// the parameter 'username' with its value 'johndoe'
curl_setopt($ch, CURLOPT_POSTFIELDS,"username=johndoe");

$result= curl_exec ($ch);
curl_close ($ch);
print $result;

?>

This script will send a HTTP POST request to “target.php” pretending to be a real person sending the “username” parameter as “john doe”.

However this is not entirely convincing since the server side will automatically know that you are using a http script to send the HTTP POST request by analyzing the browser “user-agent” string. The default script will send “(HTTPRetriever/1.0)” as its user-agent.

With a little add-on, you can spoof the user-agent string inside your script just like this :

< ?php
//
// test HTTP POST submitter, using libcurl
//

// the target url which contains scripts that accepts post request
$url = "http://localhost/wtf/target.php";

// we are spoofing Yahoo Seeker bot >:)
$useragent="YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; http://search.yahoo.com/)";

$ch = curl_init();

// set user agent
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// set the target url
curl_setopt($ch, CURLOPT_URL,$url);

// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, 1);

// the parameter 'username' with its value 'johndoe'
curl_setopt($ch, CURLOPT_POSTFIELDS,"username=johndoe");

// execute curl,fetch the result and close curl connection
$result= curl_exec ($ch);
curl_close ($ch); 

// display result
print $result;

?>

so when your “bot.php” sends the request, the server logs will record that the query was sent by a “Yahoo Seeker bot” instead of a crudely coded php script.

You can spoof other browser as long as you know their user-agent string, refer to my previous post for a collection of browser user-agent strings.

No PHP cURL support?

In this case, you have a few options

  1. Use a server that support php cURL extension
  2. Compile/Install php cURL extension
  3. Use libcurlemu – php cURL extension written in pure php

Well that should cover the short crash course on how to use php cURL extension.

p/s : Although I won’t tell you how to write one directly, this is the basic of building spam bots and auto-submitter. So use your imagination (and the dark side of the force) to write the rest of the code. *evil*

You can download the source code of this tutorial here : http://mypapit.net/pub/libcurltest.zip

php,curl,webdev,libcurl,bots

Bookmark this article
  • digg
  • YahooMyWeb
  • NewsVine
  • Netvouz
  • Reddit
  • Spurl
  • Furl
  • del.icio.us
  • StumbleUpon
  • Technorati
  • TwitThis

Keep updated with this website! : Subscribe to your email

Recommended Reading

45 smashing comments for this post.

  1. Blog Portal @ Blogtal.com Said:

    Sending HTTP POST with php cURL Feb 28, 2006 4:40 AM – Mypapit’s blog @ Computers Although I won?t tell you how to write one directly, this is the basic of building spam bots and auto-submitter. So use your imagination (and the dark side of the

  2. Blog Portal @ Blogtal.com Said:

    Sending HTTP POST with php cURL Feb 28, 2006 4:40 AM – Mypapit’s blog @ Computers Although I won?t tell you how to write one directly, this is the basic of building spam bots and auto-submitter. So use your imagination (and the dark side of the

  3. Journalism Hope | Is there Hope for Journalism? Yes, there is. Said:

    Sending HTTP POST with php cURL ? (mypapit) New Media Musings: Give out phone number, stay anonymous On the Media –June 2, 2006 Chaos, Revisited A little while ago, Bob took out his crystal ball, and looked into the brave new media future. What he saw didn

  4. lilang Said:

    provide chinese jade carve,furniture,wood carving,antique furniture,antique,antiques,bronze,carve panel,china jade carving,lamps arts,antique jade,curio,earring,sculpture,chinese furniture, sculpture, pendants, jade factory,jade provider,shanghai,beijing….

  5. lortab Said:

    lortab

  6. Auto submitter - Find The Best Auto submitter Resources Online Said:

    [...] ? Auto submitter – Find The Best Auto submitter Resources Online Auto submitter Top Auto submitter Resources Blog Submitter – ShoutBox Submitter Promotion tools, marketing Blog submitter, blog auto submitter, blog submission, blog auto submission, Blogs Submission mass blog spammer every blog auto submission it Softwares suggestions for suggest a site – A Public Forum Sponsored and Here are three suggestions 1) "suggest a site" step four: "Auto-submission software is a violation of this procedure. Sites submitted automatically are Free Web Submission: Free Search Engine Submission and Site PromotionFree Web Submission is the source for free search engine submission. We provide webmasters and site owners with free manual and auto submission to the Promoting Your Website, Josiesque Designs, website design, media You shouldn't use an auto submitter to submit to Yahoo and Open Directory. Take your time and craft your submissions carefully to these two important sites. Purdue University Cooperative Education:Other Areas, Purdue Posted by auto submitter on September 07, 2005 at 06:14:51:. Anyone can make a site popular. Not everyone will If you ever wished to be on the top of Iggys Filthy Files – Web LinksVisit rSubmitter – Auto Submitter Linkdumps Popular, Last Update: 2005/5/14 5:55 Visit Chameleon TGP and MGP Submitter – Auto, Manual TGP/MGP Submitter Free URL Submission Search Engine Add SiteThe search engines and directories are constantly changing their submission routines which causes auto-submission programs to quit functioning. Making the Most of Auto-Submitters – Part 1 – Webmaster JointWe will then take a look at several of the top auto-submission programs you Since the advent of the TGP Auto-Submitter, a great deal of controversy has Safelist Submitter – #1 Rated Auto-Safelist Submitter – SMASSAuto Safelist Submitter – Safelist Advertising – Safelist Script – Safelist Directory.FamilyReunion.com? | Resource Guide Auto-SubmissionConnect your family at the web's favorite family reunion destination.Purdue University Cooperative Education:Other Areas, Purdue auto submitter is just at your fingertips – auto submitter September 07, 2005 at 06:14:51. SPRING 2005 SUBLEASE close to campus – Jason Schlosser August 17, Adult Insider – Adult Webmaster ResourcesThe most powerfull adult webmaster submission tool. Auto submit to 700 sites. The Submission Assistant is not an auto submitter. Search Engine Submission Software Internet Marketing Dynamic With new manual submission features you have absolute control over the submission process. Some engines like Alta vista do not accept auto-submission unless Scripts and SoftwareFree Tgp Auto Submitter featuring 2 submissions modes (quick, normal). It also includes a free tgp list of 1500 sites with Email confirmer, gallery creator The-DDL.InFo – NEW Auto-SubmitterINFO ON YOUR PAGE OR YOU WILL BE BANNED FOREVER FROM USING THIS AUTO SUBMITTER. If you find your site is on/not on the list, feel free to contact me to get SafeListJunction.com – THE COMPLETE INTERNATIONAL ONLINE SAFELIST Auto safelist submitter for easy bulk email advertising. Over 1000 lists! Auto join, auto verify, auto send.Auto Submitter: Chameleon – Klixxx Forums: Adult Webmaster Message Old 03-22-2005, 01:45 PM. Raven. I Was Here First! Join Date: Jan 2002. Location: WA. Posts: 8419. Default Auto Submitter: Chameleon Script Library : CGI/PERL – URL SubmittersAuto-Submission-Pro utilizes its own built in domain spider to recognize the Auto URL Submitter Pro lets your visitors or customers submit their web Sending HTTP POST with php cURL ? (mypapit)p/s : Although I won?t tell you how to write one directly, this is the basic of building spam bots and auto-submitter. So use your imagination (and the dark Search Engine Esoterica: Context, Mispellings & Other Unnatural The reason you don't get one answer is that there are legion answers and that's too many to leave up to any auto-submitter. Content, best/most pragmatic Siteowners – webmaster forums – I think i blew my chance with all I would advise 'against' any auto submitter, do it by hand, manually submit to dmoz first, and be sure to get some healthy inbound links to your site & the Web Promotion Search Engine Submission & Internet Marketing SoftwareSome engines like Altavista, DMOZ etc. do not accept auto-submission unless you enter right submission code or choose correct category. SafelistBoys — FREE Safelists for you!SafelistBoys is a powerful automated SafelistPoster.Safelist Submitter – #1 Rated Smass Auto-Safelist Submitter BlasterOver the last 2 years we've been continually developing and releasing an auto-safelist submitter now commonly known as SMass?. With its many features our Boing Boing: A Directory of Wonderful Things(4) Our space lasers will vaporize your auto-submitter. Don't even think about using submission scripts. Only hand-crafted submissions from real humans get SMASS Auto Safelist Submitter free download. Discover the software SMASS Auto Safelist Submitter free download. Discover the software thousands of Internet marketers are using daily to generate more sales, referrals and ellbatads.com – Safelist Submitter – #1 Rated Auto-Safelist SubmitterAutomatically Blast Your Email Messages safely and legally to Thousands of Targeted Prospects using amazing set and forget technology, no monthly fees.Gallery TGP Submitter – free tgp submissions advanced submitter Auto TGP Submitter. Product Price:. Free or Premium. Product Version:. Server Edition v2.5. Product Usage:. TGP Submission Kick Azz Auto SubmitterKick Azz Auto Submitter. Welcome to the Kick Azz Auto Submitter We have developed an automatic safe list submitter that will blast your ads to thousands eBay: Submit your website 1 task with submission results to (item eVirtuWeb Auto-Submission System has been designed for membership, down-line, Mlm or any other website that would like to provide submission services for About This Auto submitter Site Welcome to this site dedicated to cushions and various related products. This site has been designed to provide a one stop resource for a wealth of information, this page is for Auto submitter related information. You can find more useful and new information from here. [...]

  7. Pueraria Mirifica Said:

    Good site I found … Plan on coming back later.

  8. shilpa rimal Said:

    we are hiring a person,who is interested to work a simple home based research works.
    its interesting ,your own environment,and sorrounding.
    there is no selling,no recruting nor ads.
    please visir
    http://www.typeinternational.com/id=7900

  9. Fred Jonsen Said:

    How do you send more than one field in your post? Thanks!

  10. Linux1.no | Vis Temaet - Automatisk pålogging på en webside Said:

    [...] Jeg har selv kun gjort det gjennom PHP, som beskrevet i denne guiden: http://blog.mypapit.net/2006/02/sending-http-post-with-php-curl.html Men jeg ser ikke bort i fra at det kan gjøres direkte med curl også, altså uten PHP. Så setter du opp en cron-jobb som kjører PHP-scriptet, som enten logger deg inn hver 6. time, eller som bruker curl for å laste ned en ekstern side for å teste om forbindelsen er oppe. [...]

  11. iman Said:

    great ideas, but what about cookie
    ? is this support it ?

  12. Free Rapidshare Premium Accounts Said:

    Thankz !

  13. Sending multiple pieces of data - Pixel2Life Forum Said:

    [...] Well you can go about this two, maybe 3 ways.The first way i would suggest is by using cURL to submit the form. A couple of examples for you:http://www.wagerank.com/2007/how-to-submit-forms-with-php/http://blog.mypapit.net/2006/02/sending-ht…h-php-curl.htmlThe second way is similar to the first but without cURL using steam_context_create. (Remember obviously recreate POST not GET )An example for you here:http://netevil.org/node.php?nid=937And the third, not very good way of doing it would be to use javascript to submit the form with an external action on your page load. However the first two would be much better, especially if wanting to spam someone Matt This post has been edited by Matthew.: Jun 2 2007, 08:41 AM ——————– – [...]

  14. Chat Said:

    Thank You!

  15. sending HTTP POST using curl command » Linux by Examples Said:

    [...] Mypapit has written a good post illustrate how to create a simple bot script using php with curl bindings. By calling curl function in php, you can do a HTTP POST to a web server’s page. Well, with curl command in bash, you can do the same, and it consist of just one line. [...]

  16. if Said:

    1234

  17. ifd Said:

    dd

  18. ifd Said:

    asd

  19. Sohbet Said:

    http://www.KankaSohbet.Net Türkiye’nin En KaliteLi Sohbet Sitesi.

  20. you Said:

    Hey buddy,
    read the manual again!
    your tut is bullshit!

  21. sohbet Said:

    thnx

  22. Sohbet Said:

    thanks

  23. sohpet Said:

    thankss

  24. havalandırma Said:

    thanksss

  25. izolasyon Said:

    thankssss

  26. bilard Said:

    Great and excellent article it’s realy helpful. Thanks again.

  27. Aksaray Said:

    Thanks

  28. aÅŸk Said:

    thankss

  29. muhabbet Said:

    thanks

  30. irc Said:

    http://www.ircrehberi.com

  31. americaminor Said:

    look english no joke stone house student clean america frog you apple ugly

  32. Babak Said:

    That’s exactly what I was looking for.
    Thank you.

  33. tteommxtee Said:

    Hello my friend, your site is very good! http://xcgdhkhfvvkhgm.com

  34. muhabbet Said:

    thank you admin

  35. aÅŸk ÅŸiirleri Said:

    Thanks webmaster very nice

  36. Sanny Said:

    thanks, cool script

  37. 出会い Said:

    さわやかな恋の予感!

  38. Dinesh Said:

    It actually solved my purpose…. guddos :)

  39. ??? Said:

    Amazing blog thanks admin
    ???

  40. sohbet Said:

    I’m happy to see the team grow. If you guys ever open up a Whistler office let me know, I’m so in

  41. sohbet chat Said:

    Very cool app. Can you tell me where to download the Help files? Apparently they didn’t make it during the install process, so it won’t load them. Thanks!

  42. sohbet odalar? Said:

    Wow. This is a very useful and informative article. You definitely not only know your stuff, you know how to illustrate your point well. Great work.

  43. Oto Teknik Servis Said:

    verly coop thakns

  44. Modern Furniture India. Said:

    The CasaModern your exclusive online design gallery and resource guide brings collections from modern, contemporary traditional, and other designer furniture manufacturers and showrooms in Italian and European interior designs for your home, office, villa, luxury apartment, service apartment, call center, hotel, cafe, pub, restaurant, and other fine living space requirement!

  45. sohbet Said:

    other designer furniture manufacturers and showrooms in Italian and European interior designs for your home, office, villa, luxury apartment, service apartment, call center, hotel, cafe, pub, restaurant..

Leave a Comment

Subscribe by email

Enter your Email