Fsockopen is a more useful function in PHP, the following I will introduce the use of Fsockopen function to collect Web pages of the program, there is a need for friends to refer to.
Usage
int Fsockopen (string hostname, int port, int [errno], string [errstr], int [timeout]);
A collection of web instances
| The code is as follows |
Copy Code |
< p>!--? php function get_url ($url, $cookie =false) { $url = Parse_url ($url); $query = $url [path]. "?". $url [query]; echo "Query:". $query; $fp = Fsockopen ($url [host], $url [port]? $url [port]:80, $errno, $errstr, 30); if (! $fp) { return false; } else { $request = "GET $query http/1.1rn"; $request. = "Host: $url [Host]rn"; $request. = "Connection:closern"; if ($cookie) $request. = "Cookie: $cookien"; $request. = "RN"; Fwrite ($fp, $request); while (! @feof ($fp)) { $result. = @fgets ($fp, 1024x768); } Fclose ($FP); return $result; } } //Get the HTML portion of the URL, remove the header function geturlhtml ($url, $cookie =false) { $rowdata = Get_url ($url, $cookie); if ($rowdata) { $body = stristr ($rowdata, "rnrn"); $body =substr ($body, 4,strlen ($body)); return $body; } return false; } ? |
The workaround after being disabled
The server also disables Fsockopen Pfsockopen, which is replaced by other functions, such as stream_socket_client (). Note: The parameters for Stream_socket_client () and Fsockopen () are different.
Fsockopen (Replace with Stream_socket_client (, then, the port parameter "80" in the original Fsockopen function is deleted and added to the $host.
Cases
| The code is as follows |
Copy Code |
$fp = Fsockopen ($host, $errno, $errstr, 30); Or $fp = Fsockopen ($host, $port, $errno, $errstr, $connection _timeout); After modification: $fp = Stream_socket_client ("tcp://". $host. " ", $errno, $errstr, 30); Or $fp = Stream_socket_client ("tcp://". $host. ":". $port, $errno, $errstr, $connection _timeout); |
http://www.bkjia.com/PHPjc/444623.html www.bkjia.com true http://www.bkjia.com/PHPjc/444623.html techarticle Fsockopen is a more useful function in PHP, the following I will introduce the use of Fsockopen function to collect Web pages of the program, there is a need for friends to refer to. Usage int fsockopen (string hostn ...