A brief analysis of the solution to the disabled php fsockopen function of the virtual host server_PHP tutorial

WBOY
Release: 2016-07-21 14:59:29
Original
1004 people have browsed it

1. How to disable fsockopen()
The following are two commonly used methods to disable fsockopen.
1. Modify php.ini and add fsockopen after disable_functions =
2. Modify php.ini and change allow_url_fopen = On to allow_url_fopen = Off

2. How to solve the problem that the fsockopen function is disabled
1. If the server does not disable pfsockopen at the same time, directly replace the fsockopen function with pfsockopen.
Specific operation: Search for the string fsockopen( in the program and replace it with pfsockopen(. The example is as follows
Before modification:
$fp = fsockopen($host, 80, $ errno, $errstr, 30);
Modified:
$fp = pfsockopen($host, 80, $errno, $errstr, 30);
2. If the server also disables pfsockopen, use other functions instead, such as stream_socket_client(). Note: The parameters of stream_socket_client() and fsockopen() are different.
Specific operation: Search for the string fsockopen in the program. (Replace with stream_socket_client(, then delete the port parameter "80" in the original fsockopen function and add it to $host. The example is as follows
Before modification:
$fp = fsockopen($host, 80, $errno, $errstr, 30);
After modification
$fp = stream_socket_client($host."80", $ errno, $errstr, 30);
3. What should I do if the PHP version is lower than 5.0, fsockopen is disabled, and there is no stream_socket_client()? Write a function to implement the fsockopen function, reference code:

Copy 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 above code to the top of it, 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, the b_fsockopen function failed to return the file pointer. You need to continue to modify the code segment: replace with socket_read( Remove fread(, use socket_write( to replace fwrite(), use socket_close( to replace fclose().

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/328145.htmlTechArticle1. How to disable fsockopen() The following are two commonly used methods to disable fsockopen. 1. Modify php.ini and add disable_functions = followed by fsockopen 2. Modify php.ini and add allow_url_...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!