Link to home
Start Free TrialLog in
Avatar of Johnny
JohnnyFlag for United States of America

asked on

sessions and mysql problem

i have a session logon that works fine

i can save the info to mysql just fine and when a member uses the logout it takes the info out just fine.

what im looking to find out is how can i detect if a session expired(a member closed the browser without loging out)
and delete the nessary mysql info.

how can i do this please
if you need any code or have any questions by all means ask please
thx
Avatar of Giovanni G
Giovanni G
Flag of Italy image


this is a FAQ. you can not detect when sesssion expires. Try looking to the following PAQ if that helps.

https://www.experts-exchange.com/questions/20890175/Sessions-Time-Out.html#10410041
Avatar of Johnny

ASKER

hrrrm

i have a few ideas but i was hoping for a better one...

i can get the files in session dir:
--------------------------
session_start();
 
/**
 * Calculate the number of users online by
 * counting the number of session files. Returns the
 * number of users on success, or -1 on failure.
 */
function getUsersOnline() {
    $count = 0;
 
    $handle = opendir(session_save_path());
    if ($handle == false) return -1;
 
    while (($file = readdir($handle)) != false) {
        if (ereg("^sess", $file)) $count++;
    }
    closedir($handle);
 
    return $count;
}
 
echo "users online = " . getUsersOnline();
--------------------------
by changeing the above code to look inside the files for below info
useing session_save_path() and insted of counting the files look in them

inside session file:
First_Name|s:6:"Johnny";Player_Name|s:4:"Trox";

now useing the above code couldnt someone look inside the files and see if one maches the user in htis case "Trox"
if it finds it it does not change the mysql info if it does not it changes it as a mantenance thing first at lets say when a page is opened(php page)

this would in affect garbage collection for if a users is curently online or not...and has a session or not
im not advanced enoph to understand how to do this, any help would be really nice please


wouldnt this idea work?
ASKER CERTIFIED SOLUTION
Avatar of Richard Quadling
Richard Quadling
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just as a side note, from PHP manual:

> Note: If you are using the default file-based session handler, your filesystem must keep track of access times (atime). Windows FAT does not so you will have to come up with another way to handle garbage collecting your session if you are stuck with a FAT filesystem or any other filesystem where atime tracking is not available. Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you won't have problems with filesystems where atime tracking is not available.

this means that you are messing with session files you must be sure not to open them in write mode, but only in "r" mode otherwise garbage collection won't work anymore.
Avatar of Johnny

ASKER

some how i think we got really lost on what im looking to do...

let me start off with saying i have windows xp ntfs files system with php 5.05

now heres what i did and need.

i made a logon system to lock pages for a memebership, this is bery basic (LOW security stuff) just a games spoilers.

so i made it logon at that time its sets sessons of players name and password then it saves msql info of is a person login to the web site(flips a varible to 1 for on and 0 for logoff) and saves the time this was done so we know how long they have been on the site.
 so ive came up witha  prrblem of changing this info if a user is not on the web site anymore or has closed the browser. i have set my sessions to garbage collect the files everytime the sesions are fired so next time a user comes in it will be actrute(as so far we have only 6 members and will most lilly not have more then 25).

so i need to be able to change the mysql var to know the user has loged off. i saw you can know where the files are for the sesions so why can we read them via php and see if a users inside of it.. if it is it leaves the file alone and if there not there it re ajusts the mysql varible, thus makingit a live whos online and accurate too.

theres gotta be some way alot of bbs(or fourms) have whos online(with in 5 mins) this would be a bit more acurate tho this way would it not.

the getUsersOnline() function seams to COUNT the files in the session directory. so why cant we then know that we open this file and look for the players name then use that to search the mysql db tables for the info we need to adjust or not.
i just dont know enoph about php to do this..the proper code. (when ive asked questins here ive been amazed that its completly diffrent code then what i evan thought it be.. due to speed and other things in side of codeing. but in this case im looking for jUST to be done code. but again i havent a clue on that at all here)
thanks for any help provided
Avatar of Johnny

ASKER

ok i have changed this to a mysql session handler

i still have the problem of updateing my mysql data to reflect the change of logout..

so i need to see if the users inthe session info still and if not update the info in logon info tables...

please see this ee question maybe you can ll help fix this problem

for now im going to give RQuadling  and a grade of B (as my question WAS NOT handled and not answered correctly at all
i was looking to update mysql info with finding a way to detect the expired session..i can do this now in mysql session handler(got the right path to find that info from RQuadling) again grade B was due to i did come up with a way to do this and no one answered it full..and insted of asking for a refund(or to close this question) i gave the points to RQuadling
i hate asking for a refund or close question(should be a way to automate this with a check box EE if your listening)
thanks for the help