The solution to disabling the phpfsockopen function of the VM server is analyzed. 1. how to disable fsockopen () The following are two common methods to disable fsockopen. 1. modify php. ini, add disable_functions to fsockopen2, modify php. ini, and set allow_url _
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.
Specific operation: Search for the string fsockopen in the program (replace with pfsockopen (. 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:
The code is as follows:
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 operation: 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 (replace it with B _fsockopen (.
2. because the fsockopen function returns the file pointer, it can be operated by the file function, but this B _fsockopen function does not return the file pointer. you need to modify the code segment: use socket_read (replace fread (, use socket_write (replace fwrite (and use socket_close (replace fclose (.
Disable () is a common method to disable fsockopen. 1. modify php. ini, add disable_functions = to fsockopen 2, modify php. ini, and add allow_url _...