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 :
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
- Use a server that support php cURL extension
- Compile/Install php cURL extension
- 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
thank you…
This script is exactly what I was looking for…my search ends here…
Hello,
very interesting script.
Could you provide some advice on how to make a POST request to a jsp form with curl?
Thanks in advance!
Hello,
very interesting script.
Could you provide some advice on how to make a POST request to a jsp form with curl?
Thanks in advance!
Thank you for sharing your article I would always follow.
Great post, really help me alot. Thanks.
thanks you adminastor..
thanks nice sharing
thak you
hello to everyone who has blog.first I congratulate the blog owner.he is got excellent blog.actually I read all your articles from weary and your writing very attractive waiting to continue thanks
thank you..
thanks admin have a nice day
Hi great article. I want to publish this article on my own if allowed.
good very goodl
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..
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!
verly coop thakns
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.
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!
I’m happy to see the team grow. If you guys ever open up a Whistler office let me know, I’m so in
Amazing blog thanks admin
???
It actually solved my purpose…. guddos :)
ã•ã‚ã‚„ã‹ãªæ‹ã®äºˆæ„Ÿï¼
thanks, cool script
Thanks webmaster very nice
thank you admin
Hello my friend, your site is very good! http://xcgdhkhfvvkhgm.com
That’s exactly what I was looking for.
Thank you.
look english no joke stone house student clean america frog you apple ugly
http://www.ircrehberi.com
thanks
thankss
Thanks
Great and excellent article it’s realy helpful. Thanks again.
thankssss
thanksss
thankss
thanks
thnx
Hey buddy,
read the manual again!
your tut is bullshit!
http://www.KankaSohbet.Net Türkiye’nin En KaliteLi Sohbet Sitesi.
asd
dd
1234
Thank You!
Thankz !
great ideas, but what about cookie
? is this support it ?
How do you send more than one field in your post? Thanks!
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
Good site I found … Plan on coming back later.
lortab
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….