PHP uses the File_get_contents proxy method to get the code for the Remote Web page.
Copy Code code as follows:
<?php
$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 curl way to use the proxy:
Copy 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;
}
using file_get_contents to solve the problem of Ajax collapse
In AJAX usage, sometimes the domain call file is overwhelmed, and the browser warns the operation by default for security, or even blocks it directly. If it is IE will pop up a warning window, ask if you continue to operate, only if you agree to IE will call down the domain file. and other browsers, such as Firefox, opera default settings will be directly prompted errors, blocking the call to the Outland file. This will give users a bad operation experience, if you want to change the browser's security settings to solve this problem is not realistic, preferably on the server side to resolve.
On the server side, you can use a file of the same domain as the proxy file, which will get the contents of the Outland file and then pass it to Ajax. So Ajax is not to call the Outland file, but to call the same domain of this proxy file, security issues are resolved.
If your server side supports PHP, you can use the File_get_contents function to see its name and know that it has access to other file content. Its detailed usage can be read from the File_get_contents usage page on the PHP official website, and here is a simple example of it.
Copy Code code as follows:
<?php
$serverAddress = ' http://s.jb51.net ';
Get the contents of the Outland file
$randomNumber = file_get_contents ($serverAddress);
Output content
Echo $randomNumber;
?>