Search code examples
phpmysqlsqlsessionsession-hijacking

PHP Session - Multiple Users With 1 IP


On Monday, I thought I had solved the session hijacking security issue by setting the session as the user IP, until I logged in. I had two users with the same IP (myself and a test user) and it kept switching between the two. Is there a way to prevent this and allow two users with the same IP register on my site?

Thanks in advance, Terry.


Solution

  • You may have been reading advice about storing the user's IP in a table along with the session id (not in place of). You'd then check to make sure they're coming from the same IP on subsequent requests, otherwise, force them to login again. This method has problems as well a user's ip can change as often as every ten minutes depending on their ISP!

    Use the session id provided by PHP as it's unique and difficult to guess. Require it to be read from a cookie and never from the URL.