Discuz教程网

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

[复制链接]
authicon gram 发表于 2013-4-10 17:57:41 | 显示全部楼层 |阅读模式
系统升级后,发现有个远程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. 302 Found
  2. [align=center][size=1]302 Found[/size]
  3. [/align]
  4. [align=center]nginx[/align]
复制代码
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]rnurl: $urlrnpost: $postrnrn", 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.0rn";
  10. $out .= "Accept: */*rn";
  11. //$out .= "Referer: $boardurlrn";
  12. $out .= "Accept-Language: zh-cnrn";
  13. $boundary = $encodetype == 'URLENCODE' ? '' : ';'.substr($post, 0, trim(strpos($post, "n")));
  14. $out .= $encodetype == 'URLENCODE' ? "Content-Type: application/x-www-form-urlencodedrn" : "Content-Type: multipart/form-data$boundaryrn";
  15. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
  16. $out .= "Host: $host:$portrn";
  17. $out .= 'Content-Length: '.strlen($post)."rn";
  18. $out .= "Connection: Closern";
  19. $out .= "Cache-Control: no-cachern";
  20. $out .= "Cookie: $cookiernrn";
  21. $out .= $post;
  22. } else {
  23. $out = "GET $path HTTP/1.0rn";
  24. $out .= "Accept: */*rn";
  25. //$out .= "Referer: $boardurlrn";
  26. $out .= "Accept-Language: zh-cnrn";
  27. $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]rn";
  28. $out .= "Host: $host:$portrn";
  29. $out .= "Connection: Closern";
  30. $out .= "Cookie: $cookiernrn";
  31. }
复制代码
我把其中第78行和第90行的代码:
  1. $out .= "Host: $host:$portrn";
复制代码
改为如下:
  1. $out .= "Host: $host".($port==80?"":":$port")."rn";
复制代码
就正常了。。。



上一篇:3.0手机触屏版下登陆提示404
下一篇:互动百科的discuz7.2关闭 因为discuz漏洞
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-4 00:50

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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