For server security considerations, many host vendors disabled php's fsockopen function. They blog yesterday and use cos-html-cache to generate static files. Nima prompts: Warning: fsockopen () hasbeendisabledforsecurityreasonsinD: cos-html-cachecos-html-cachephpon
For server security considerations, many host vendors disabled php's fsockopen function. They blog yesterday and use cos-html-cache to generate static files. Nima prompts: Warning: fsockopen () has been disabled for security reasons in D :... cos-html-cachecos-html-cache.php on line 35
Cos-html-cache of other versions is not supported. Then find the following method. =, (The result is invalid because the functions are disabled .) We have tried to replace functions with other methods.
1. how to disable fsockopen ()The following are two common methods to disable fsockopen.
1. modify php. ini and add disable_functions = to fsockopen.
2. modify php. ini and change allow_url_fopen = On to allow_url_fopen = Off.
II. how to disable the fsockopen function
1. if the server does not disable pfsockopen at the same time, replace the fsockopen function with pfsockopen. for details, replace the fsockopen string in the search program with pfsockopen. for example:
Before modification: $ fp = fsockopen ($ host, 80, $ errno, $ errstr, 30 );
After modification: $ fp = pfsockopen ($ host, 80, $ errno, $ errstr, 30 );
2. if pfsockopen is disabled on the server, use other functions, such as stream_socket_client (). Note: the parameters of stream_socket_client () and fsockopen () are different.
Specific operation: Search for the character string fsockopen in the program (replace it with stream_socket_client (, and then delete the port parameter "80" in the original fsockopen function and add it to $ host. Example:
Before modification: $ fp = fsockopen ($ host, 80, $ errno, $ errstr, 30 );
After modification: $ fp = stream_socket_client ($ host. "80", $ errno, $ errstr, 30 );
3. what if fsockopen is disabled and stream_socket_client () is not available if PHP version is earlier than 5.0? Write a function to implement the fsockopen function. refer to the code:
- Function B _fsockopen ($ host, $ port, & $ errno, & $ errstr, $ timeout ){
- $ Ip = gethostbyname ($ host );
- $ S = socket_create (AF_INET, SOCK_STREAM, 0 );
- If (socket_set_nonblock ($ s )){
- $ R = @ socket_connect ($ s, $ ip, $ port );
- If ($ r | socket_last_error () = EINPROGRESS ){
- $ Errno = EINPROGRESS;
- Return $ s;
- }
- }
- $ Errno = socket_last_error ($ s );
- $ Errstr = socket_strerror ($ errno );
- Socket_close ($ s );
- Return false;
- }
Specific operations:
1. first find the code segment using the fsockopen function, add the code above to its upper end, search for the string fsockopen in the code segment and replace it with B _fsockopen.
2. because the fsockopen function returns the file pointer, it can be operated by the file function. However, this B _fsockopen function does not return the file pointer. you need to modify the code segment: replace fread with socket_read, and replace fwrite with socket_write, replace fclose with socket_close.
Solution 2:Most fsockopen applications obtain remote page data. for applications that obtain remote pages, PHP has other functions that can be perfectly replaced. Method 1:
-
- $ Str = file ("http://www.phpfensi.com ");
- $ Count = count ($ str );
- For ($ I = 0; $ I <$ count; $ I ++ ){
- $ File. = $ str [$ I];
- }
- Echo $ file;
- ?>
Method 2:
-
- $ Str = file_get_contents ("http://www.phpfensi.com ");
- Echo $ str;
- ?>