datasn.io
datasn.io

Reputation: 12867

Session not persisting on bare IP address website 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?

Upvotes: 0

Views: 270

Answers (1)

Quentin
Quentin

Reputation: 944005

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.

Upvotes: 3

Related Questions