Sending HTTP POST with php cURL

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

A rather large collection of browser User-agent strings

If you are into analyzing http log files or writing web applications that does user-agent analysis, you might appreciate this website PGTS Agent String Switchword. The website has a huge collection of browser user-agent list ranging from the common Mozilla/Internet Explorer variant to search-engine spider, malicious web bots and internet worms.

The list is organised in various orders to ease up browsing (alphabetical, operating system, by popularity, common robots user agent). Finally, the site also offers tab-delimited user-agent download (zip file). This is useful for those who want to build user-agent database for their own project.

AJAX Web applications with Yahoo UI Library !

Yahoo Developer Network has released the Yahoo! User Interface Library. It is a toolkit library written in Javascript for building web applications by utilising DOM scripting, XHTML and AJAX (XMLHttpRequest).

The library is designed to simplify web development and to enhance web experience for the web applications users. Among things that included in the library are :

  • Animations
  • Connection Manager
  • DOM
  • Drag and Drop
  • Event
  • Calendar
  • Slider
  • Treeview

The Yahoo! UI Library is released under the BSD License. Please refer to http://developer.yahoo.net/yui/ for more information.

yahoo, ajax, webdev, yahoo.com,dom, javascript

Funny Google Groups Malay Translations

I’ve some trouble with my php code, so I decided to search around php mailing list for some xml-rpc implementations specific solutions. Since google groups has tons of mailing list archives, I decided to start there first. After few minutes of reading for possible solutions and ideas, I decided to try out the Google Groups syndication feed, because I was curious about it.

My curiousity paid out because I finally saw Google began using ATOM 1.0 syndication format, but shortly after that, my eyes scan down the page and I read something that makes me laugh out loud! Apparently Google has taken the translation thingy too seriously by over-translating proper nouns.

Can you guess what Google mean by “makananSetan”, “RuangBawah”, “beritaGator” and “JaringanBeritaWayar” in the screenshot below? (p/s: they are all in Malay language)

I really don’t want my feed ends up to be makananSetan…

google, google.com, funny, google+groups, translations, malay, malaysia

Promote your blog through Blogtal.com (Blog Portal)

Hey, I just found out about this new cool website http://www.blogtal.com/, that can help expose your blog to greater viewers. Bloggers can promote their blog by adding their latest post to Blogtal’s listing through a form. Once filled, your post will be visible on the frontpage of Blogtal, and will be kept inside their database for at least 30 days.

Users of WordPress and MovableType can use the trackback feature to auto-submit their latest post to Blogtal. WordPress users can use Ah Knight’s Default Trackback plugin or Autotrackback plugin.

You can subscribe to the latest post from Blogtal (mostly malaysian blog) via its RSS feeds.

blogtal, blog, blogs, weblog, wordpress, aggregator, blogging

Google denies plan releasing Google Desktop OS

Following the report from TheRegister, another new source, Ars Technica, published that Google spokeperson denies their plan to release the so-called “Goobuntu” operating system.

The source however quoted that Google has been using Ubuntu internally but has no plan to built their own operating system based on Ubuntu.

debian,ubuntu,google,google.com