PHP uses File_get_contents's proxy method to get the code for a remote Web page.
Copy the Code code as follows:
$url = "http://www.jb51.net/";
$ctx = stream_context_create (Array (
' http ' = = Array (' timeout ' = 5,
' Proxy ' = ' tcp://60.175.203.243:8080 ',
' Request_fulluri ' = True,)
)
);
$result = file_get_contents ($url, False, $ctx);
echo $result;
?>
Another way to use the Proxy method is curl:
Copy the Code code as follows:
function Postpage ($url)
{
$response = "";
$rd =rand (1,4);
$proxy = ' http://221.214.27.253:808 ';
if ($rd ==2) $proxy = ' http://222.77.14.56:8088 ';
if ($rd ==3) $proxy = ' http://202.98.123.126:8080 ';
if ($rd ==4) $proxy = ' http://60.14.97.38:8080 ';
if ($url! = "") {
$ch = Curl_init ($url);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_proxy, $proxy);
$response = curl_exec ($ch);
if (Curl_errno ($ch)) $response = "";
Curl_close ($ch);
}
return $response;
}
Solving the problem of Ajax collapse with file_get_contents
In the application of Ajax sometimes the call file, and the browser for security will default to this operation to warn, or even directly block. If IE will pop up a warning window asking if you want to continue, only if you agree to IE will call the collapsed file. Other browsers, such as Firefox and Opera, will prompt the error directly, blocking the calling of an alien file. This will give the user a bad operating experience, if you want to modify the browser's security settings to solve the problem is not realistic, preferably in the server-side solution.
On the server side can use a same domain file as proxy file, this proxy file will get the content of the other files, and then passed to Ajax. In this way, Ajax is not the calling of an alien file, but the proxy file of the same domain, and the security issue is resolved.
If you have a server-side support for PHP, you can use the File_get_contents function, see its name to know that it has the ability to get other file content. Its detailed usage can be see the PHP official website on the File_get_contents usage page, below is its simple example.
Copy the Code code as follows:
$serverAddress = ' http://s.jb51.net ';
Get the contents of an alien file
$randomNumber = file_get_contents ($serverAddress);
Output content
Echo $randomNumber;
?>
The above describes the file_get_contents PHP through the file_get_contents agent use, including the file_get_contents aspects of the content, I hope that the PHP tutorial interested friends have helped.