File_get_contents is blocked. In php, the file_get_contents function can directly collect remote server content and save it to a variable, generally, the file_get_contents, fsockopen, and other IO operation functions can be directly collected by the file_get_contents function in php, and then saved to a variable, generally, file_get_contents, fsockopen, and other IO functions are disabled because they are afraid of DDOS attacks.
In general, we can't change the server's inc. php. we can only write a set of IO to replace the above PHP function.
| The code is as follows: |
|
|
$ Url = file_get_contents ('http: // www. bKjia. c0m /');
|
We can use the following code instead.
| The code is as follows: |
|
|
// How to disable file_get_contents
$ Ch = curl_init ();
$ Timeout = 10; // set to zero for no timeout
Curl_setopt ($ ch, CURLOPT_URL, 'http: // www.hzhuti.com /');
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
$ Url = curl_exec ($ ch ); |
Curl is a tool that uses URL syntax to transmit files and data. it supports many protocols, such as HTTP, FTP, and TELNET, and is not disabled by the server, therefore, we can open a URL like file_get_contents.
Use the function_exists function to determine whether php supports a function. you can easily write the following function.
| The code is as follows: |
|
<? Php
Function vita_get_url_content ($ url ){
If (function_exists ('File _ get_contents ')){
$ File_contents = file_get_contents ($ url );
} Else {
$ Ch = curl_init ();
$ Timeout = 5;
Curl_setopt ($ ch, CURLOPT_URL, $ url );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, $ timeout );
$ File_contents = curl_exec ($ ch );
Curl_close ($ ch );
}
Return $ file_contents;
}
?> |
...