Perhaps Fsockopen, Pfsockopen function does exist security risks, but we have no research, this is the IDC business, no matter what the reason, anyway, they are to disable the two functions, then how to solve it, the following is a small arrangement of methods, Hope that the use of the students have a certain reference.
The workaround is as follows:
First, use Stream_socket_client () instead
The server also disables Fsockopen, Pfsockopen, and replaces it with other functions, such as stream_socket_client (). Note: The parameters for Stream_socket_client () and Fsockopen () are different.
Specific actions:
The string Fsockopen in the search program (replaced by Stream_socket_client (), and then the port parameter "80" in the original Fsockopen function is deleted and added to the $host.
Examples are as follows:
Before modification:
Copy Code code as follows:
$fp = Fsockopen ($host, $errno, $errstr, 30);
Or
Copy Code code as follows:
$fp = Fsockopen ($host, $port, $errno, $errstr, $connection _timeout);
After modification:
Copy Code code as follows:
$fp = Stream_socket_client ("tcp://". $host. " 80″, $errno, $errstr, 30);
Or
Copy Code code as follows:
$fp = Stream_socket_client ("tcp://". $host. ":". $port, $errno, $errstr, $connection _timeout);
Ii. rewriting of the law
What if PHP version below 5.0,fsockopen is disabled, and there is no stream_socket_client ()? Write a function of your own to implement Fsockopen function, reference code:
Copy Code code 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 actions:
1. First find the code snippet that uses the Fsockopen function, add the above code to its top, and search for the string fsockopen in the code snippet (replaced by B_fsockopen.
2. Because the Fsockopen function returns a file pointer so it can be manipulated by a file function, but this b_fsockopen function does not return a file pointer, and you need to continue modifying the code snippet: replace the fread with the Socket_read (Socket_write ( Replace the fwrite (, with Socket_close () Replace the fclose (.
In the above method, I use stream_socket_client () substitution problem to solve, the second method did not try.