Question: I have an application, which is written in codeigniter.
I use CI provided session library for session management purposes.
It is deployed on live.

When I connect the application to WiFi or LAN in my laboratory (college) network, session data get unsetted randomly. And the application logs out the current user.

But when I connect it to my hotspot, it works fine.
So I wanted to ask whether the sessions are affected by network type.

Answer: 
After monitoring the logs,
I understood the following points,

* There is a parameter in the session library `sess_match_ip`
* first, you have to set it to false
* then you have to check whether the following loop in session library is getting executed or not,

```
if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI>input->ip_address())

    {
        $this->sess_destroy();
        return FALSE;
    }

```
* if it is, then you need to comment out the loop or remove that block of code entirely.
I know this is not the permanent solution but it worked for me.

The reason behind this happening is,

Some networks switch ips very rapidly, so if the IP at the time of token creation and request are different, that session is destroyed, according to the code mentioned.

Thank you.
If the IP changes *while you are logged in* and that seems to be causing the user to log-out, it's probably because CI sessions can be configured (or not) to enforce that sessions are tied to an IP address. Please note that while this is easily configurable, if you're using CI's database driver for session data, you'll need to alter the session table depending on the value assigned to this parameter

> 
> *application/config/config.php*
> 
> 
> 

```
| 'sess_match_ip'
|
|   Whether to match the user's IP address when reading the session data.
|
|   WARNING: If you're using the database driver, don't forget to update
|            your session table's PRIMARY KEY when changing this setting.

$config['sess_match_ip'] = FALSE;

```

Assigning `FALSE` as the value, will permit that a user remains logged-in even if the IP changes. Your session configuration probably is set to `TRUE`, which means that a different client IP will cause the session to be no longer valid.

If you are not using database as the session driver, all you need to do is change the `sess_match_ip` parameter and you are set. 
If you are using database for sessions, the changes you need to perform are in the CI documentation here:

[Session Library](https://www.codeigniter.com/user_guide/libraries/sessions.html#database-driver)

Specifically, this:

```
You will also need to add a PRIMARY KEY depending on your ‘sess_match_ip’ setting. The examples below work both on MySQL and PostgreSQL:

// When sess_match_ip = TRUE
ALTER TABLE ci_sessions ADD PRIMARY KEY (id, ip_address);

// When sess_match_ip = FALSE
ALTER TABLE ci_sessions ADD PRIMARY KEY (id);

// To drop a previously created primary key (use when changing the setting)
ALTER TABLE ci_sessions DROP PRIMARY KEY;

```