本帖最后由 ddyii2 于 2012-1-25 16:19 编辑
关于fsockopen pfsockopen函数被禁用的解决方法 一、
服务器同时禁用了fsockopen pfsockopen,那么用其他函数代替,如stream_socket_client()。注意:stream_socket_client()和fsockopen()的参数不同。
具体操作:
搜索程序中的字符串 fsockopen( 替换为 stream_socket_client( ,然后,将原fsockopen函数中的端口参数“80”删掉,并加到$host。
示例如下
修改前:
$fp = fsockopen($host, 80, $errno, $errstr, 30);
修改后:
$fp = stream_socket_client($host."80", $errno, $errstr, 30);
二、
如果PHP版本低于5.0,fsockopen被禁用,又没有stream_socket_client()怎么办呢?自己写一个函数实现fsockopen的功能,参考代码:
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;
}
具体操作:
1.首先找到使用fsockopen函数的代码段,将上面代码加至其上端,搜索该代码段中的字符串 fsockopen( 替换为 b_fsockopen( 。
2.因为fsockopen函数返回文件指针所以可以被文件函数操作,但是这个b_fsockopen函数没能返回文件指针,需要继续修改代码段:用socket_read( 替换掉 fread( ,用socket_write( 替换掉fwrite( ,用socket_close( 替换掉fclose( 。
http://www.13800.net
方法二:
通用解决方法:
找到程序里的fsockopen 函数,替换为:pfsockopen,即可解决所有问题,两个函数的区别在于pfsockopen 保持keep-alive,使得黑客无法进行 连接数攻击。
已知使用fsockopen 函数的程序文件路径(在fsockopen 前加p, 即fsockopen 修改为pfsockopen 即可 )[其他程序可通过错误提示的文件路径查看更改]:
Discuz X2 安装提示不支持fsockopen:
将/include/install_var.php 文件里的
$func_items = array(‘mysql_connect’, ‘fsockopen‘, ‘gethostbyname’, ‘file_get_contents’, ‘xml_parser_create’);
替换为:
$func_items = array(‘mysql_connect’, ‘pfsockopen‘, ‘gethostbyname’, ‘file_get_contents’, ‘xml_parser_create’);
即可正常安装。
X2全部包含fsockopen的文件(如果用邮件只修改邮件即可,其他文件都是自动判断pfsockopen):
\api\manyou\Manyou.php
\api\trade\api_alipay.php
\install\include\install_function.php
\install\include\install_lang.php
\install\include\install_var.php
\source\admincp\admincp_addons.php
\source\admincp\admincp_checktools.php
\source\admincp\admincp_cloud.php
\source\admincp\admincp_misc.php
\source\admincp\cloud\cloud_doctor.php
\source\class\class_image.php
\source\class\class_sphinx.php
\source\class\block\xml\block_xml.php
\source\function\function_connect.php
\source\function\function_core.php
\source\function\function_filesock.php
\source\function\function_importdata.php
\source\function\function_mail.php 邮件相关
\source\function\function_plugin.php
\source\include\portalcp\portalcp_upload.php
\source\language\lang_admincp_cloud.php
\source\module\forum\forum_ajax.php
\source\module\misc\misc_manyou.php
\uc_client\client.php
\uc_client\lib\sendmail.inc.php 邮件相关
\uc_client\model\misc.php
\uc_server\install\func.inc.php
\uc_server\install\lang.inc.php
\uc_server\lib\sendmail.inc.php 邮件相关
\uc_server\model\misc.php
Discuz 品牌空间不能安装,提示UC地址不正确:
修改/install/func.inc.php 里的fsockopen函数为pfsockopen
Discuz 7.2:(非首次安装,可以只改绿色部分。)
问题:使用uc 不能登录 ,fsockopen函数位于:
include\global.func.php(240): $fp = @fsockopen(($ip ? $ip : $host),$port, $errno, $errstr, $timeout);include\sendmail.inc.php(54): if(!$fp= fsockopen($mail['server'], $mail['port'], $errno, $errstr, 30)){install\func.inc.php(803): $fp = @fsockopen(($ip ? $ip : $host),$port, $errno, $errstr, $timeout);install\var.inc.php(70): $func_items= array('mysql_connect', 'fsockopen', 'gethostbyname','file_get_contents', 'xml_parser_create');uc_client\client.php(211) fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr,$timeout);uc_client\lib\sendmail.inc.php(40): if(!$fp =fsockopen($mail_setting['mailserver'], $mail_setting['mailport'],$errno, $errstr, 30)) {uc_client\model\misc.php(97): $fp =@fsockopen(($ip ? $ip : $host), $port, $errno, $errstr,$timeout);uc_server\lib\sendmail.inc.php(40): if(!$fp =fsockopen($mail_setting['mailserver'], $mail_setting['mailport'],$errno, $errstr, 30)) {uc_server\model\misc.php(94): $fp =@fsockopen(($ip ? $ip : $host), $port, $errno, $errstr, $timeout);
|