{"action":"created","issue":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4102","labels_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4102/labels{/name}","comments_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4102/comments","events_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4102/events","html_url":"https://github.com/bcit-ci/CodeIgniter/issues/4102","id":105448756,"number":4102,"title":"When `sess_match_ip` is enabled, moving to a new IP address causes an error","user":{"login":"natesilva","id":160467,"avatar_url":"https://avatars.githubusercontent.com/u/160467?v=3","gravatar_id":"","url":"https://api.github.com/users/natesilva","html_url":"https://github.com/natesilva","followers_url":"https://api.github.com/users/natesilva/followers","following_url":"https://api.github.com/users/natesilva/following{/other_user}","gists_url":"https://api.github.com/users/natesilva/gists{/gist_id}","starred_url":"https://api.github.com/users/natesilva/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/natesilva/subscriptions","organizations_url":"https://api.github.com/users/natesilva/orgs","repos_url":"https://api.github.com/users/natesilva/repos","events_url":"https://api.github.com/users/natesilva/events{/privacy}","received_events_url":"https://api.github.com/users/natesilva/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-08T19:00:40Z","updated_at":"2015-09-08T21:16:53Z","closed_at":"2015-09-08T21:16:53Z","body":"→ Yes, I have read the manual and enabled the additional `UNIQUE` index described there!\r\n\r\nIn `Session_database_driver.php`, in the `read()`, method, the logic to determine if the row exists seems wrong.\r\n\r\nThe query looks like this:\r\n\r\n```php\r\n$this->_db\r\n\t->select('data')\r\n\t->from($this->_config['save_path'])\r\n\t->where('id', $session_id);\r\n\r\nif ($this->_config['match_ip'])\r\n{\r\n\t$this->_db->where('ip_address', $_SERVER['REMOTE_ADDR']);\r\n}\t\r\n```\r\n\r\nSo, if `match_ip` is enabled, this looks for a row where both `id` and `ip_address` match.\r\n\r\nBut the table definition (from <http://www.codeigniter.com/user_guide/libraries/sessions.html#database-driver>) has `id` as a primary key.\r\n\r\nThus there could *never* be two rows for a given `id` with different `ip_address`es.\r\n\r\nThat means the suggested constraint:\r\n\r\n`ALTER TABLE ci_sessions ADD CONSTRAINT ci_sessions_id_ip UNIQUE (id, ip_address);`\r\n\r\n…has no practical effect, because `id` must be unique anyway.\r\n\r\n### Workaround\r\n\r\nSomething that works, and what I think the documentation may have been trying to say, is **changing the primary key** from `id` to `(id, ip_address)` if you plan to use `sess_match_ip`.\r\n"},"comment":{"url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/comments/138703035","html_url":"https://github.com/bcit-ci/CodeIgniter/issues/4102#issuecomment-138703035","issue_url":"https://api.github.com/repos/bcit-ci/CodeIgniter/issues/4102","id":138703035,"user":{"login":"narfbg","id":1058011,"avatar_url":"https://avatars.githubusercontent.com/u/1058011?v=3","gravatar_id":"","url":"https://api.github.com/users/narfbg","html_url":"https://github.com/narfbg","followers_url":"https://api.github.com/users/narfbg/followers","following_url":"https://api.github.com/users/narfbg/following{/other_user}","gists_url":"https://api.github.com/users/narfbg/gists{/gist_id}","starred_url":"https://api.github.com/users/narfbg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/narfbg/subscriptions","organizations_url":"https://api.github.com/users/narfbg/orgs","repos_url":"https://api.github.com/users/narfbg/repos","events_url":"https://api.github.com/users/narfbg/events{/privacy}","received_events_url":"https://api.github.com/users/narfbg/received_events","type":"User","site_admin":false},"created_at":"2015-09-08T21:16:53Z","updated_at":"2015-09-08T21:16:53Z","body":"8 days ago: 20573bd472bdeaa831074e563f239585554ffaf5"}}