There are few examples of PHP bot programs on the Web, which is also a business requirement, and it is very interesting to start contacting such programs. The so-called bot is actually simulate get or post, to action some programs, to achieve some automated processing, of course, this thing is a double-edged sword, but do not be bad.
PHP implementation of the bot there are a variety of ways, individuals prefer httprequest, one more oo, and to write simple and convenient. Here is the class corresponding function, and there are some examples.
function can be directly clicked into the official PHP API, interested friends to go to visit; Method name is very intuitive, not much explanation. Example #1 Get Example
Code
$r = new HttpRequest (' Http://example.com/feed.rss ', httprequest::meth_get);
$r->setoptions (Array (' LastModified ' => filemtime (' Local.rss '));
$r->addquerydata (Array (' Category ' => 3));
try {
$r->send ();
if ($r->getresponsecode () = = 200) {
File_put_contents (' Local.rss ', $r->getresponsebody ());
}
catch (HttpException $ex) {
Echo $ex;
}
?>
This example simulates get to request an RSS subscriber, also addquerydata such a get query parameter, and then executes send, sending the GET request when the Getresponsecode is 200, which is when the bot succeeds, Stores the response HTML returned by a GET request into a local file.
Example #2 POST Example
Code
$r = new HttpRequest (' http://example.com/form.php ', httprequest::meth_post);
$r->setoptions (Array (' Cookie ' => array (' lang ' => ' de '));
$r->addpostfields (' user ' => ' Mike ', ' Pass ' => ' s3c|r3t '));
$r->addpostfile (' image ', ' profile.jpg ', ' image/jpeg ');
try {
echo $r->send ()->getbody ();
catch (HttpException $ex) {
Echo $ex;
}
?>
This example simulation post to request a PHP file, post not by addquerydata such function, but through the addpostfields to set up the analog input form, and then execute send, Returns the response HTML echo from the POST request to the current page in PHP.