SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    session unseting doubt

    hello friends here i am having some doubt like i am updating my status while the user is loging in and out but if the user closed the browser without logout how can i update my status in db to show the user is current more i dont need to fix the timer like the browser is closed means my session is unseting but the db is not updating so how can i do it pls help any body knows through code

  2. #2
    Non-Member thewebhostingdir's Avatar
    Join Date
    Oct 2005
    Posts
    703
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sessions last for a particular interval depending upon your server setting or timeout setting in your code. You can periodically check the number of active sessions and then close the sessions if the session ID is not available when you echo it.

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hello friend then somebody i have seen using this onunload function and all ?friend if u know the code for the timer for the session pls sent me .. because the code with me is not working ........

  4. #4
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    thewebhostingdir is correct, the best way to find out who has left is to keep an active record of everyone and their last page view times. If the person hasn't had a page view within a certain time, you can assume they have left.

    Sessions will time out on their own accord, within a timeout set by your server. It's generally been about 15 minutes in my experience but I haven't really thought about session timeouts in a few years, so the standard timeout may have changed.

  5. #5
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Onunload refers to the page unloading, however you cannot differentiate between someone 'leaving' the page to go to another page, and someone 'leaving' to leave the site completely.

    I guess you could have an ajax call on every unload function that tags them as having left a page, and if they don't enter another page within a certain time then flag them as logged out, however you're getting into some very complicated methods there and I imagine you should probably be re looking at what you are actually trying to achieve.

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you friend for a quick reply i left out my website and made know just for pages like login,secondpage,logout,register where the timer i fixed is not working properly can u give me a timer code friend pls if u can thank u for the good in formation and path way...so waiting for ur good reply to solve my timer problem

  7. #7
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    I'm not really sure what your existing timer script does, and if that script provides the solution that you're after it's probably best to get in touch with the people who supplied you with that script and get them to investigate your issues.

    All I would be doing is completely rewriting a solution for a problem which I don't really understand.

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok friend thanks for an active reply like i am fixing an timer in the login page,second page
    where the timer function is as below

    $start=time();
    $_SESSION['time_start']=$start;

  9. #9
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    You've started the session first?

    PHP Code:
    <?PHP
    // Before ANYTHING else in the script, including white space
    session_start();

    ?>

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes i have started session and all but no use .... its not validating the time and unseting the session if u have any sample notes for timer give me.... ok friend

  11. #11
    SitePoint Evangelist
    Join Date
    Jun 2006
    Location
    Wigan, Lancashire. UK
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mal Curtis View Post
    Onunload refers to the page unloading, however you cannot differentiate between someone 'leaving' the page to go to another page, and someone 'leaving' to leave the site completely.
    Remember that onUnload is also called on a page refresh
    ---
    Development Projects:
    PHPExcel
    PHPPowerPoint

  12. #12
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    13 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kuttus011 View Post
    $start=time();
    $_SESSION['time_start']=$start;
    So that code is storing the timestamp into a session variable. Is there any other code that's happening?

    This on its own is not really doing anything...

  13. #13
    SitePoint Zealot
    Join Date
    Jul 2009
    Posts
    152
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ya i know it my friend so what i am searching for it but i got a way to compare the date difference but no use so still searching for the fixing a timer for the session if any of the other friends know how to fix pls reply through the code bcoz what ever code examples i am seeing in the net is not working properly...

  14. #14
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    A simple method would be to have a field in the database saying 'last active', which you update whenever the user makes a HTTP request (i.e. going to a new page or making an AJAX call etc).

    You can then find out the users which are still logged in with the following MySQL Query:
    Code sql:
    SELECT col1, col2, etc FROM users WHERE NOW() < LastActivity + INTERVAL 15 MINUTES

    Disclamer: My MySQL knowledge is terrible when it comes to handling dates/times, so the above may not work... But you can probably figure it out
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •