I received a few PM`s on this, so here the functional "idea" behind this script.
First we create a function wich will return us a "session" id that is based on the "row" id of the session table. We will set this value in the "$_SESSION vars so we can validate it.
*------ The Function -----------*
First we create a "cleanup" script that will remove all "old" sessions from the table so each "page refresh" will give us "up-to-date" information about all the sessions.
The Cleanup will be triggered based on a "timestamp" of +15Mins. If session is "older" then these 15 Mins the session will / should be removed from the database.
Next we should handle the "current" session. If $_SESSION was allready set then this is an "old user" for he allready triggered this function before. If this is the case, we check if the previous "page refresh" was within these "15 mins" else the session was lost and we notify the user (if logged in) else we just create a new session.
If the $_SESSION wasnt set, this means this user "triggered" this script for the first time. In this case we dont need to validate anything, this because we have a new guest browsing.
Ladder
+------+Call the function.
|
+Run the Cleanup Script to validate all sessions (key current time).
| To remove all sessions of "left" users (closed browser or left website)
|
+Validate $_SESSION (isset)
|
?Yes / No?
|
+ Yes +
| |
| +Check Session age (+15mins)?
| |
| <15
| | Update Timestamp -> Return(Row ID)
| |
| |
| 15>
| If Logged in, Logout and "return logout" message
| Create new Session as Guest > Return (Row ID)
|
|
+NO+
Create new Session as Guest > Return(Row ID)
- Ladder
- +------+Call the function.
- |
- +Run the Cleanup Script to validate all sessions (key current time).
- | To remove all sessions of "left" users (closed browser or left website)
- |
- +Validate $_SESSION (isset)
- |
- ?Yes / No?
- |
- + Yes +
- | |
- | +Check Session age (+15mins)?
- | |
- | <15
- | | Update Timestamp -> Return(Row ID)
- | |
- | |
- | 15>
- | If Logged in, Logout and "return logout" message
- | Create new Session as Guest > Return (Row ID)
- |
- |
- +NO+
- Create new Session as Guest > Return(Row ID)
-May