- $ Url = "http://bbs.it-home.org /";
- $ 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;
- ?>
2. curl proxy method:
- Function postPage ($ url)
- {
- $ Response = "";
- $ Rd = rand (1, 4 );
- $ Proxy = 'http: // 212.33.27.253: 8080 ';
- If ($ rd = 2) $ proxy = 'http: // 212.88.16.56: 8088 ';
- If ($ rd = 3) $ proxy = 'http: // 202.98.123.126: 8080 ';
- If ($ rd = 4) $ proxy = 'http: // 59.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;
- }
Appendix: use php file_get_contents to solve the problem of ajax cracking domain In ajax application, sometimes the domain call file is broken, and the browser sends a warning or even directly blocks this operation for security. 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 the server supports PHP, you can use the file_get_contents function. for detailed usage, see http://www.w3school.com.cn/php/func_filesystem_file_get_contents.aspexample:
- $ ServerAddress = 'http: // s.jbxue.com ';
- // Obtain the external domain file content
- $ RandomNumber = file_get_contents ($ serverAddress );
- // Output Content
- Echo $ randomNumber;
- ?>
|