Php reads remote website content [anti-piracy]-PHP source code

Source: Internet
Author: User
Php reads remote website content [anti-leech] php reads remote website content [anti-leech]

Script ec (2); script

This is a way to use php fsockopen to read the content of the remote server. The method of this section of the program is to use anti-theft. Let's take a look at it.

Function DownloadToString ()
{
$ Crlf = "rn ";
$ Response = "";
// Generate request
$ Req = 'get'. $ this-> _ uri. 'HTTP/123'. $ crlf
. 'Host: '. $ this-> _ Host. $ crlf
. $ Crlf;

// Fetch
$ This-> _ fp = @ fsockopen ($ this-> _ protocol = 'https '? 'Ssl: // ': ''). $ this-> _ host, $ this-> _ port );
@ Fwrite ($ this-> _ fp, $ req );
While (is_resource ($ this-> _ fp) & $ this-> _ fp &&! Feof ($ this-> _ fp ))
$ Response. = fread ($ this-> _ fp, 1024 );
@ Fclose ($ this-> _ fp );

// Split header and body
$ Pos = strpos ($ response, $ crlf. $ crlf );
If ($ pos = false)
Return ($ response );
$ Header = substr ($ response, 0, $ pos );
$ Body = substr ($ response, $ pos + 2 * strlen ($ crlf ));

// Parse headers
$ Headers = array ();
$ Lines = explode ($ crlf, $ header );
Foreach ($ lines as $ line)
If ($ pos = strpos ($ line ,':'))! = False)
$ Headers [strtolower (trim (substr ($ line, 0, $ pos)] = trim (substr ($ line, $ pos + 1 ));

// Redirection?
If (isset ($ headers ['location'])
{
$ Http = new HTTPRequest ($ headers ['location']);
Return ($ http-> DownloadToString ($ http ));
}
Else
{
Return ($ body );
}
}
}

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.