The fsockopen and pfsockopen functions of PHP are disabled by the host service provider. The fsockopen and pfsockopen functions of PHP are disabled by the host service provider. the fsockopen functions may have security risks, however, the fsockopen and pfsockopen functions of PHP cannot be tested.
Maybe the fsockopen and pfsockopen functions do have security risks, but we have no research. this is what IDC vendors say, no matter what the reason is, anyway, they disabled these two functions. how can they be solved? below is a small compilation method, hoping to have some reference for those who are using it.
The solution is as follows:
I. use stream_socket_client () to replace
If both fsockopen and pfsockopen are disabled on the server, use other functions, such as stream_socket_client (). Note: the parameters of stream_socket_client () and fsockopen () are different.
Specific operations:
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:
The code is as follows:
$ Fp = fsockopen ($ host, 80, $ errno, $ errstr, 30 );
Or
The code is as follows:
$ Fp = fsockopen ($ host, $ port, $ errno, $ errstr, $ connection_timeout );
After modification:
The code is as follows:
$ Fp = stream_socket_client ("tcp: //". $ host. "80", $ errno, $ errstr, 30 );
Or
The code is as follows:
$ Fp = stream_socket_client ("tcp: //". $ host. ":". $ port, $ errno, $ errstr, $ connection_timeout );
II. rewrite method
If PHP version is earlier than 5.0, fsockopen is disabled, and stream_socket_client () is not available, what should I do? 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 operations:
1. first find the code segment that uses the fsockopen function, add the code above to its top, and 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 (.
In the above method, I used stream_socket_client () to solve the problem. The second method did not try.
Win's host has disabled the functions fsockopen and pfsockopen, and cannot call APIs. how can this problem be solved?
Let me tell you the address.
How Can I disable the fsockopen pfsockopen function in a wordpress program installed on a VM?
To modify fsockopen pfsockopen, you need to modify the PHP configuration file php. ini, which is a file of the PHP program and placed in the PHP Directory. it is not a file of wordpress.
Wordpress is a web page program that uses PHP for parsing. the Function on which wordpress depends must be supported by PHP. to change the PHP configuration, go to the directory where PHP is located and find php. ini.
Maybe the fsockopen and pfsockopen functions do have security risks, but we have no way to test them...