Since you mention PHP, I will include information from the PHP manual. I believe that other languages behave the same.
On the server, the session is cookie specific. From the PHP manual :
Session identifiers are usually sent to the browser through session cookies, and the identifier is used to retrieve existing session data. The absence of an identifier or session cookie allows PHP to know in order to create a new session and generate a new session identifier.
In a user agent (client, usually a browser), cookies are specific to the domain and path. From RFC6265 , section 4.1.2.3:
The Domain attribute indicates the sites to which the cookie will be sent. For example, if the Domain attribute value is "example.com", the user agent will include the cookie in the Cookie header when making HTTP requests to example.com, www.example.com, and www.corp.example. com
Section 4.1.2.4:
The user agent will only include cookies in the HTTP request if part of the uri-uri path matches (or is a subdirectory) the Paths cookie attribute, where the% x2F ("/") character is interpreted as a directory separator.
So, if you navigate from a domain name to an IP address, for example, example.com and 12.34.56.78 , the session cookie created by the server for example.com will not be sent by the user agent if you later make a request at 12.34.56.78 , even if both are the same server. With a later request, since the server does not see the session cookie, a new session is created and a new cookie is sent. For this, using both a domain name and an IP address, separate sessions will be used.
If you need to use the same session when using the domain name and IP address, you need to keep the session identifier between requests. A common method is to pass the session identifier in the query string. In fact, PHP session management can also be configured to use this method, but I never need to use it, so I can’t tell you how this will happen.
Continuing my example, you can use it for subsequent queries:
http:
Where abcdef0123456789 is an example of a session identifier.
In the PHP code, set the session identifier before calling session_start() . Code example:
if(isset($_GET['sessionId'])) session_id($_GET['sessionId']); @session_start();
Of course you do not need to use sessionId . You can use foobar or anything else. You can also change it daily or even hourly to prevent session hijacking.
Update: To use foobar , change the PHP code to this:
if(isset($_GET['foobar'])) session_id($_GET['foobar']); @session_start();
With this code, you can pass in the session ID as follows:
http:
If you want to use xyz , the PHP code will look like this:
if(isset($_GET['xyz'])) session_id($_GET['xyz']); @session_start();
You can pass the session id as follows:
http:
The fact is that it really is up to you.