dongye1143
dongye1143
2017-04-11 15:22
浏览 98
已采纳

会话不持久裸IP地址网站111.222.333.444:5566

The same PHP script I'm using works fine with sessions on a domain website like example.com but not so when it's uploaded and accessed on a bare IP address website with an arbitrary HTTP port number like this:

111.222.333.444:5566

Variables can be set in $_SESSION which is accessible in the same PHP request but they are gone with the next page load.

Tried this:

session_set_cookie_params(
    0,
    '/',
    '111.222.333.444:5566'
);

session_start();

But it's not working. Also checked phpinfo() and the bare IP site's session is enabled. My browser does support cookie when both of the tests are run.

This is weird. What could be wrong here? Is PHP session meant to not persist on bare IP site with exotic HTTP port?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzhangwei5265
    douzhangwei5265 2017-04-11 15:24
    已采纳

    One of the requirements for cookies is:

    The string is a host name (i.e., not an IP address).

    You can't associate a cookie with an IP address, only with a hostname.

    PHP sessions depend on session cookies to work.

    点赞 评论

相关推荐