Use the file_get_contents function to pass the dongle in seconds

Source: Internet
Author: User

Author: y0umer this function is known to anyone familiar with PHP. It can obtain local content or support remote content capturing through HTTP or FTP. However, file_get_contents is discarded when an HTTP header or COOKIE is sent. After in-depth research by the husband, we found that the file_get_contents function can also send HTTP headers. Function prototype: String file_get_contents (string $ filename [, bool $ use_include_path [, resource $ context [, int $ offset [, int $ maxlen]) the first parameter is the file name, and the second parameter is whether it is in php. if the init_path function is configured in ini, the third parameter can send an HTTP header. For details, see the code: <? Php $ options = array ('http' => array ('cookie '=> 'phpsessionid = 1231467477', 'method' => 'get ')); $ context = stream_context_create ($ options); $ code = file_get_contents (' http://www.baidu.com/index.php ', False, $ context);?> Code explanation: function prototype: Resource stream_context_create ([array $ options [, array $ params]) stream_context_create creates and returns a text data stream and applies various options for fopen (), file_get_contents. In this way, our file_get_contents function has the ability to send HTTP header, of course, can also be used for fopen and other functions. We will not talk much about it. The following code adds a timeout value to the file_get_contents function: <? Php $ options = array ('http' => array ('timeout' => 10 // 10 ms); $ context = stream_context_create ($ options ); $ code = file_get_contents (' http://www.baidu.com/index.php ', False, $ context);?> Combined with the above instance, a safe dog exp php version: <? Php $ url = empty ($ _ GET ['url'])? $ _ GET ['url']: ''; $ options = array ('http' => array ('user-agent' => 'baidu' // forge a browser into a hundred-degree spider .)); $ context = stream_context_create ($ options); $ code = file_get_contents ($ url, false, $ context); Echo $ code;?> In fact, fsockopen and socket functions are similar. But file_get_contents is recommended ..References:Http://www.bkjia.com/kf/201305/209937.html
Http://www.bkjia.com/net/201305/209939.html

Related Article

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.