PHP uses the File_get_contents proxy method to get the code for the Remote Web page.
Copy CodeThe code is 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 CodeThe code is 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 experience if they want to modify the browser's Security SettingsTo solve this problem is not realistic, preferably on the server side of the solution.
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 CodeThe code is as follows:
<?php
$serverAddress = ' http://s.jb51.net ';
Get the contents of the Outland file
$randomNumber = file_get_contents ($serverAddress);
Output content
Echo $randomNumber;
?>
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