PHP fsockopen Function Description:
Open Internet or Unix domain socket connection (open socket link)
Initiates a socket connection to the resource specified by target.
Fsockopen () Returns a file pointer which may is used together with the other file functions (such as fgets (), FGETSS (), Fwrite (), fclose (), and feof (). is to return a file handle
Open PHP Fsockopen This function
The PHP fsockopen requires php.ini allow_url_fopen option to open.
Use Fsockopen to get web content
The specific source code is as follows:
<?php
$host = "www.manongjc.com";
$page = "/index.htm";
$fp = Fsockopen ("$host", $errno, $errdesc);
if (! $fp) {
die ("couldn ' t connect to $host: \nerror: $errno \ndesc: $errdesc \ n")
;
$request = "Get $page http/1.0\r\n";
$request. = "Host: $host \ r \ n";
$request. = "referer:http://www.manongjc.com/page.html\r\n";
$request. = "user-agent:php test client\r\n\r\n";
$page = Array ();
Fputs ($fp, $request);
while (! feof ($fp)) {
$page [] = fgets ($fp, 1024);
}
Fclose ($FP);
Print "The server returned". (count ($page)). Lines! ";
? >
Above is the PHP source code fsockopen Get the content of the Web page details of the knowledge, there is a need for small partners can refer to, thank you for the support of this site!