Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$_SERVER['SERVER_ADDR'] 在mac php7中获取不到 #520

Closed
dongm2ez opened this issue Oct 20, 2016 · 2 comments
Closed

$_SERVER['SERVER_ADDR'] 在mac php7中获取不到 #520

dongm2ez opened this issue Oct 20, 2016 · 2 comments

Comments

@dongm2ez
Copy link

dongm2ez commented Oct 20, 2016

使用支付报错,报错是

"return_code" => "FAIL"
"return_msg" => "spbill_create_ip参数长度有误"

查找源码 在获取这个值的地方扫码支付使用的是
function get_server_ip()
{
// for php-cli(phpunit etc.)
if (empty($_SERVER['SERVER_ADDR'])) {
return gethostbyname(gethostname());
}

return $_SERVER['SERVER_ADDR'];

}

但是 $_SERVER['SERVER_ADDR'] 是空的,而获取的gethostbyname(gethostname()) 为本机的机器名不是IP地址

@jinchun
Copy link
Contributor

jinchun commented Oct 21, 2016

#522

我的测试环境phpversion()打印的结果是 7.0.8-2+deb.sury.org~xenial+1,没重现你说的问题。
另外 gethostbyname() 如果获取的是本机的机器名而不是IP地址,通常是因为你的机器名没指向127.0.0.1 。(这个之前是为了解决 phpunit 等 cli 命令而作的)

@dongm2ez
Copy link
Author

ok,已经解决了,谢谢你

overtrue pushed a commit that referenced this issue Oct 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants