Php source code fsockopen to get web page content examples, fsockopen web page content

Source: Internet
Author: User
Tags unix domain socket

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!

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.