it allows me to update their row instead of deleting them and readding them to the databasePHP Code:$query = mysql_query("update tbOnline set username='".$_SESSION["tbUser"]."',time = '$timeSession' where session='$sessionNumber'");
Printable View
it allows me to update their row instead of deleting them and readding them to the databasePHP Code:$query = mysql_query("update tbOnline set username='".$_SESSION["tbUser"]."',time = '$timeSession' where session='$sessionNumber'");
I see that but you don't have to use the id of the session, but you could use the username or the password. I was just curious as you said you wanted to know how to do it by using a session.
carry on :)
I have to do it by id because what if they are not logged in? Then they have a session ID inside the database but with the username field out as guest
Then when they login their username changes to whatever username they are using on my site.
-Matt
oh I see. it doesn't matter if they are logged in or not you still put them in the database. thier session anyway... gotcha ya :)
Yeah, sorry for not mentioning that earlier. I decided to track both Guests and Members on the site.
-Matt
i was reading this, maybe itll help?
Quote:
If you propagate the session ID via cookies, the default cookie lifetime is 0, meaning that the cookie is deleted as soon as the user closes the browser. You can influence the cookie's lifetime with the configuration value lifetime.
Sorry to ask this, but how does this apply to me? Im not sure I understand. (I just want to ensure im not making a massive mistake somewhere too)
-
I found a problem with my earlier code, so the following fixes that error. The error was 1) it was set to only track a user for a second, 2) if the user opened a new browser window and went to your site he could be logged as two sessions, so that is taken care of now.
Enjoy!PHP Code:session_start();
$_SESSION["tbUser"]; // Variable that stores the Username
$_SESSION["tbPass"]; // Variable that store their password with an md5 encryption
$sessionNumber = session_id(); // Grabs their session ID Number
if ($tbUser == "") $tbUser = ""; // Checks to see if they are a guest
$timeSession = time(); // Grabs the current time
$querySession = "select * from tbOnline"; // Select the entire table
$resultSession = mysql_query($querySession);
$numSessions = mysql_numrows($resultSession); // Number of rows returned
$countSession = 0;
while ($countSession < $numSessions) { // Continue till all rows are checked for inactivity
$idSession = mysql_result($resultSession,$countSession,"id"); // Grabs the session ID of the row
$sessionStart = mysql_result($resultSession,$countSession,"time"); // Grabs the last time they were count as active (last time they loaded a page)
if ($sessionStart+300 < $timeSession) // If the current time is more than 5 minutues from when they were last considered active they need to be removed
$query = mysql_query("delete from tbOnline where id='$idSession'");
$countSession++;
}
$foundUser = mysql_numrows(mysql_query("select * from tbOnline where session='$sessionNumber' or (username='$tbUser' and session='$sessionNumber')")); // Check to see if I have a user inside the table that either has the same session Id number or the same username (then update it accordingly)
if ($foundUser == 0)
$query = mysql_query("insert into tbOnline (username,time,session) values ('$tbUser', '$timeSession','$sessionNumber')");
else
$query = mysql_query("update tbOnline set username='$tbUser',time = '$timeSession' where session='$sessionNumber'");
I found this. Might be of interst.
cool, cause that is pretty much how mine works.
-Matt
You're a smart man :)