In PHP, use the file_get_contents proxy method. in PHP, use the file_get_contents proxy method to obtain the code of the remote webpage.
The code is 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 curl method uses proxy:
The code is as follows:
Function postPage ($ url)
{
$ Response = "";
$ Rd = rand (1, 4 );
$ Proxy = 'http: // 221.214.27.253: 8080 ';
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;
}
Use file_get_contents to solve ajax domain cracking problems
In ajax applications, files are called in different domains, and browsers warn or even block such operations for security purposes by default. If it is IE, a warning window will pop up asking if you want to continue the operation. only when you agree with IE will you call the file that breaks down the domain. Other browsers, such as Firefox and Opera, receive an error by default to prevent external domain files from being called. This will give users a poor operation experience. if you want to solve this problem by modifying the security settings of the browser, it is unrealistic, preferably on the server side.
On the server side, you can use a file in the same domain as the proxy file. This Proxy file will get the content of the external domain file and then pass it to ajax. In this way, ajax does not call the external domain file, but calls the Proxy file of the same domain, and the security problem is solved.
If your server supports PHP, you can use the file_get_contents function to obtain other file content. For details about its usage, see the file_get_contents usage page on the official PHP website. Below is a simple example of this page.
The code is as follows:
$ ServerAddress = 'http: // s.jb51.net ';
// Obtain the external domain file content
$ RandomNumber = file_get_contents ($ serverAddress );
// Output Content
Echo $ randomNumber;
?>