Remove session when logging in

Asked

Viewed 165 times

2

Good morning to you all! Gentlemen, I need guidance, and I also need to know if you have what it takes. It is as follows: I have a table in my database that records users who are logged in, it follows:

inserir a descrição da imagem aqui

What I want to do is, every time a login is done (in addition to the normal login routine) is checked in this table if the guy is logged in or not. If he is logged in, I want to compare the sessions that are in the bank and the one that I will take at login time, and update the session, date and ip. If the comparison goes wrong, I want to update the new information, and the session that was there was destroyed.

Can you do that? Thanks in advance!

  • What have you tried?

  • I logged in normal, my big doubt is to destroy the registered session at the bank, and update with the new session, and in doing so, the machine where I was logged in earlier, miss the session with the bank. That part I haven’t done much yet

  • At the time of logging in, check if the date is today’s date, for example and if the login is already logged in, if it is, you delete this record and already enter another one, thus updating the :)

  • I get it. In this case, just update if the record already exists. If it does not exist, enter a new normal?

  • Also, if you want to update, otherwise delete the record and insert the new one, which gives in the same, in my opinion

2 answers

0

  1. Select the record by login field.
  2. Compare if the sc_session field equals session_id()
  3. If not equal, delete the previously selected record or update with the current data
  • Exactly as I suggested :)

  • Thank you gentlemen, I decided a while ago but I only had time to give a feedback to vcs hj. It worked well your tip. Thank you very much!

0

When logging in, delete that user’s login records, or if you prefer to put a column that identifies that situation. Place a validation right after the session is started (session_start) makes a select to check that session_id is in the table, if it is not, use session_destroy to end this session.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.