SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Location
    Mumbai- India
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Initialise session variable when user leaves the web site

    I have typical problem with session variable

    I have developed an application of placing order in rainola.com
    Functionally it words fine but if a person surf other web sites and come back to the rainola.com he can still view the order details

  2. #2
    SitePoint Addict
    Join Date
    Feb 2007
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What's the expiration time on the session?

    Alternatively, you might be able to use the referrer variable to destroy existing session if it's not from your site.

  3. #3
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the solution here is to keep record of the last time the user was seen and if it's been too long then delete all session info (limiting the session lifespan like Arlen said is a way to achieve this).

    Be wary that it could happen that the user left the window open the session would be destroyed even if the user didn't abandon the site.

    There's no way to detect if the user went to other website.

    Another option is using javascript onUnload event but, again, it is not infallible: javascript could be disabled and onUnload is fired when the users closes the window and when navigates to other site.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,788
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by joaquin_win View Post
    Another option is using javascript onUnload event but, again, it is not infallible: javascript could be disabled and onUnload is fired when the users closes the window and when navigates to other site.
    onunload (which is all lowercase as JavaScript) also fires when the page is reloaded and so would almost certainly not do what is required.

    Sessions remain until one of three things happen.
    1. Your visitor performs an action that you have set up to close the session (such as a logoff link where the session is being used when someone logs in)
    2. They close their browser
    3. The time period set on your server for session life span expires.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •