0

yes,

I think my issue is similar to this guy on this stackoverflow page. I read through prograhammer's respond. His solution seems simpler and so I tried to implement it.

  1. In my member DB Table, I created a field called "sessionID (Char32)"
  2. When user login, grab existing SessionID in DB
  3. If his current ID and DB Session ID is different, get DB Session ID and destroy it, then assign new current ID

Problem I encountered: When I login on a different browser, I got kicked out immediately, but when I login again, there is no issue. Also any browser I previously logged in is now Logged Out (This part is working correctly)

The part I don't understand is how do I actually destroy the PREVIOUS sessionID (the one in DB), and assign new current Session ID?

After user enter loginID and PW in login Page:

//Current Session ID
$sessionID = session_id();

//Get previous DB Session ID
$sql = mysql_query("select * from member where emailid = '".$user_email."' and pwd = '".$user_password."'");
$row = mysql_fetch_array($sql);
$DBSessionID=$row[sessionID];

//If current Session ID & SessionID in DB not the same
            if($sessionID != $DBSessionID)
            {
                    session_id($DBSessionID);
                    session_start();
                    session_destroy();
                    session_commit();
                    
                    session_id($sessionID);
                    session_start();
                    mysql_query("update member set sessionID='$sessionID' where emailid='$user_email'");
                    
            }
            //Else if no SessionID in DB - Update with current Session ID
            else if ($DBSessionID == "")
            {
                mysql_query("update member set sessionID='$sessionID' where emailid='$user_email'");
            }

Kind regards

user2741620
  • 305
  • 2
  • 7
  • 21
  • 1
    Please read [Why shouldn't I use mysql_* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?noredirect=1&lq=1) – brombeer Jan 17 '22 at 06:18
  • Thank you for telling me this, but what is the solution to my current issue? Is it actually related to mysql * functions? – user2741620 Jan 17 '22 at 09:56

0 Answers0