PHPBOT instance code _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.