Php source code fsockopen to get web page content examples, fsockopen web page content
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 be used together with the other file functions (such as fgets (), fgetss (), fwrite (), fclose (), and feof ()). returns a file handle.
Enable the PHP fsockopen Function
PHP fsockopen must be enabled by the allow_url_fopen option in PHP. ini.
Use fsockopen to obtain webpage content
The source code is as follows:
<?php$host = "www.manongjc.com";$page = "/index.htm";$fp = fsockopen( "$host", 80, $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!";?>
The above is the php source code fsockopen to get detailed knowledge of web content instances. If you need it, refer to it. Thank you for your support for this site!