PHP source Fsockopen Get the Web page content instance detailed _php instance

Source: Internet
Author: User
Tags php source code socket unix domain socket

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!

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.