First, how to disable Fsockopen ()
The following are two common ways to disable Fsockopen.
1, modify php.ini, will disable_functions = after adding fsockopen
2. Modify PHP.ini, change allow_url_fopen = on to Allow_url_fopen = Off
second, how to solve the Fsockopen function is disabled
1. If the server does not disable Pfsockopen at the same time, replace the Fsockopen function with Pfsockopen directly.
What to do: Search for string Fsockopen in the program (Replace with Pfsockopen (. Examples such as the following
Before modification:
$fp = Fsockopen ($host, $errno, $errstr, 30);
After modification:
$fp = Pfsockopen ($host, $errno, $errstr, 30);
2, if the server is also disabled pfsockopen, then use other functions instead, such as stream_socket_client (). Note: The parameters for Stream_socket_client () and Fsockopen () are different.
What to do: Search the program for string Fsockopen (replace with Stream_socket_client (, then, the port parameter "80" in the original Fsockopen function is deleted and added to the $host. Examples such as the following
Before modification:
$fp = Fsockopen ($host, $errno, $errstr, 30);
after modification
$fp = Stream_socket_client ($host. " ", $errno, $errstr, 30);
3, if the PHP version is less than 5.0,fsockopen is disabled, and no stream_socket_client () How to do? Write a function to implement Fsockopen function, reference code:
Copy CodeThe 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;
}
Operation: 1. First find the code snippet that uses the Fsockopen function, add the above code to its upper end, and search for the string fsockopen in the snippet (replace with B_fsockopen (.
2. Because the Fsockopen function returns a file pointer so it can be manipulated by the file function, but this b_fsockopen function does not return the file pointer, you need to continue to modify the code snippet: with Socket_read (replace Fread (, with Socket_write ( Replace the fwrite (, with Socket_close (replace the fclose (.
http://www.bkjia.com/PHPjc/328145.html www.bkjia.com true http://www.bkjia.com/PHPjc/328145.html techarticle first, how to disable Fsockopen () The following are two common ways to disable Fsockopen. 1, modify php.ini, will disable_functions = after adding Fsockopen 2, modify PHP.ini, will allow_url_ ...