Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

ucenter dfopen函数BUG:远程fopen自动带80端口,造成通信失败!

[复制链接]
qbit 发表于 2013-5-27 12:55:59 | 显示全部楼层 |阅读模式
本帖最后由 qbit 于 2013-5-27 13:02 编辑

系统升级后,发现有个远程ucenter应用测试老是通信失败,于是一步步调试查找原因,最后发现是因为ucenter中的一个函数dfopen有BUG,他老会自动带上80端口,而有些服务器碰上80端口的请求会自动302重定向到不带端口域名下,即从www.324324.cn:80重定向到www.324324.cn,这时远程调用请求就会返回302响应,造成通信失败。
  1. GET /api/uc.php?code=0690yeurtGqQZ0lp62...... HTTP/1.0
  2. Accept: */*
  3. Accept-Language: zh-cn
  4. User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.57 Safari/537.17
  5. Host: www.324324.cn:80
  6. Connection: Close
  7. Cookie:
复制代码
return data:
  1. <br><br><html>
  2. <head><title>302 Found</title></head>
  3. <body bgcolor="white">
  4. <center><h1>302 Found</h1></center>
  5. <hr><center>nginx</center>
  6. </body>
  7. </html>
复制代码
uc_server/model/msic.php第62到93行,可以看到,默认都加了80端口。
  1. function dfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE        , $ip = '', $timeout = 15, $block = TRUE, $encodetype  = 'URLENCODE') {
  2.                 //error_log("[uc_server]\r\nurl: $url\r\npost: $post\r\n\r\n", 3, 'c:/log/php_fopen.txt');
  3.                 $return = '';
  4.                 $matches = parse_url($url);
  5.                 $host = $matches['host'];
  6.                 $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
  7.                 $port = !empty($matches['port']) ? $matches['port'] : 80;

  8.                 if($post) {
  9.                         $out = "POST $path HTTP/1.0\r\n";
  10.                         $out .= "Accept: */*\r\n";
  11.                         //$out .= "Referer: $boardurl\r\n";
  12.                         $out .= "Accept-Language: zh-cn\r\n";
  13.                         $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "\n")));
  14.                         $out .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencoded\r\n" : "Content-Type: multipart/form-data$boundary\r\n";
  15.                         $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  16.                         $out .= "Host: $host:$port\r\n";
  17.                         $out .= 'Content-Length: '.strlen($post)."\r\n";
  18.                         $out .= "Connection: Close\r\n";
  19.                         $out .= "Cache-Control: no-cache\r\n";
  20.                         $out .= "Cookie: $cookie\r\n\r\n";
  21.                         $out .= $post;
  22.                 } else {
  23.                         $out = "GET $path HTTP/1.0\r\n";
  24.                         $out .= "Accept: */*\r\n";
  25.                         //$out .= "Referer: $boardurl\r\n";
  26.                         $out .= "Accept-Language: zh-cn\r\n";
  27.                         $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
  28.                         $out .= "Host: $host:$port\r\n";
  29.                         $out .= "Connection: Close\r\n";
  30.                         $out .= "Cookie: $cookie\r\n\r\n";
  31.                 }
复制代码
我把其中第78行和第90行的代码:
  1. $out .= "Host: $host:$port\r\n";
复制代码
改为如下:
  1. $out .= "Host: $host".($port==80?"":":$port")."\r\n";
复制代码
就正常了。。。


评分

1

查看全部评分

玻璃屋女孩 发表于 2013-5-27 15:48:45 | 显示全部楼层
感谢您的反馈我们排查一下
回复

使用道具 举报

 楼主| qbit 发表于 2013-5-27 22:05:35 | 显示全部楼层
希望尽快修改,虽然我自己解决了,但是老提示文件被修改过,而且每次升级又覆盖回去,很不方便。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2025-3-6 17:42 , Processed in 0.027435 second(s), 5 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表