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 );
}
}
}