PHPBOT instance code. PHPBOT instance code has very few online PHPBOT program instances. It was also a business requirement some time ago and it was very interesting to get started with such programs. The so-called BOT is actually simulating GET or php bot instance code
There are still very few instances of php bot programs on the internet. some time ago it was also a business requirement and it was very interesting to get started with such programs. The so-called BOT is actually simulating GET or POST, taking action to some programs and implementing some automatic processing. of course, this is a double-edged sword, so don't make it bad.
PHP supports multiple methods to implement BOT. I personally prefer HttpRequest, which is relatively OO and easy to compile. The following are the functions corresponding to the class and some examples.
Function can directly click to enter the official php api, and interested friends go in. the method name is very intuitive and 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, and also queries GET parameters such as addQueryData, and then executes send to send this GET request. when getResponseCode is 200, that is, when the BOT is successful, store the response HTML returned by the get request to a local file.
Example #2 POST example
Code
$ R = new HttpRequest ('http: // example.com/form.php', HttpRequest: METH_POST );
$ R-> setOptions (array ('Cookies '=> array ('Lang' => 'de ')));
$ R-> addPostFields (array ('user' => 'Mike ', 'pass' => 's3c | r3t '));
$ R-> addPostFile ('image', 'profile.jpg ', 'image/jpeg ');
Try {
Echo $ r-> send ()-> getBody ();
} Catch (HttpException $ ex ){
Echo $ ex;
}
?>
This example simulates POST to request a php file. POST does not use functions such as addQueryData, but uses addPostFields to set the simulated input form, and then executes send, echo the response html returned by the POSt request to the current PHP page.
Http://www.bkjia.com/PHPjc/847204.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/847204.htmlTechArticlePHP BOT instance code online on php bot program instances are still very few, some time ago is also the business needs, began to contact such programs, very interesting. The so-called BOT is actually simulating GET or...