Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Northern NJ
    Posts
    404
    Thanks
    0
    Thanked 1 Time in 1 Post

    Session time out

    I need to set a 15 minute window for someone to log into my site, and after 15 minutes they can no longer go to any other pages. Plus I need a counter to count down how much time they still have left. I am not sure if sessions will handle this, but after the 15 minutes are up from the time you enter the site I want all functions of the site to cease. Please help, all help is appreciated. Thank you.
    I would rather be a lion for a day than a lamb that lives forever.

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    This can not be done with sessions because sessions are rewriting and updated when you refresh the page.

    I suggest keeping track of the user by IP address in a database. This way you know who he is, when they first clicked on the link to give them 15 minutes free and how long he has left.

    Code for finding out IP:
    Code:
    UserIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
    If UserIP = "" Then
      UserIP = Request.ServerVariables("REMOTE_ADDR")
    End If
    Sometimes IPs are hidden behind proxy servers, this will help keep the IPs unique as possible.

    You also store the time and date. Then you use (everytime he refreshes a page) a script which checks the date from when he first joined.
    Code:
    DateDiff("n", theDate, Now())
    "n" = minutes
    theDate = The date in the database.
    Now() = The time when the script is ran.
    Code:
    If DateDiff("n", theDate, Now()) >= 15 Then
      Response.Write "You're 15 minutes are up"
      Response.End
    End If
    Does this help?

    For more information about the DateDiff() function.
    http://msdn.microsoft.com/library/de...ctdatediff.asp

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Northern NJ
    Posts
    404
    Thanks
    0
    Thanked 1 Time in 1 Post
    This helps plenty, but what if I want a ticker count down how much time is left how would I do that? Please let me know what you think. Also, how do I kick him/her off my site after 15 minutes? All help is appreciated.
    I would rather be a lion for a day than a lamb that lives forever.

  • #4
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    The counter is easy, you use the DateDiff() function again along with it's close personal friend the DateAdd() function, this time will have count down code. You can find many different count down scripts on aspin.com or even google.com.

    I changed the idea,
    Code:
    <%
    strDoneDate = DateAdd("n", 15, theDate)
    
    If DateDiff("n", theDate, Now()) >= 15 Then
      'This is how to kick the user from your site, he wont be able to come back, unless he changes his IP.
      Response.Redirect("kick.asp")
    Else
      StrCDDate = Now()
      strMinutes = DateDiff("n", StrCDDate, strDoneDate) - 1
      StrCDDate = DateAdd("n", strMinutes, StrCDDate)
      strSeconds = DateDiff("s", StrCDDate, strDoneDate) - 31
      Response.Write "You have <b>"
      Response.Write strMinutes & " minute</b>(<b>s</b>)<b>, and "
      Response.Write strSeconds & " second</b>(<b>s</b>) "
      Response.Write "left until you are kicked"
    End If
    %>
    theDate = The Date from the database (when the user joined)

    Enjoy!

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Northern NJ
    Posts
    404
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks for all your help. I do have one question, if you a high starting time like 12:59:59 the function you will have a negative number in the seconds at times. How can I avoid this issue?
    I would rather be a lion for a day than a lamb that lives forever.

  • #6
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    When did this problem occur? Before you tested it yourself, or after you implamented into your code?
    I tried to force this error myself, I couldn't get it to show up.

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Northern NJ
    Posts
    404
    Thanks
    0
    Thanked 1 Time in 1 Post
    interestingly enough this error does not occur anymore, but if you refresh or go to another page (that has the same script on it) at 59 seconds there is an error (NAN instead of a number for the seconds). Plus why do you add the -1 and -31 at the end of the calculations for minutes and seconds respectfully?
    I would rather be a lion for a day than a lamb that lives forever.

  • #8
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by ecnarongi
    interestingly enough this error does not occur anymore, but if you refresh or go to another page (that has the same script on it) at 59 seconds there is an error (NAN instead of a number for the seconds). Plus why do you add the -1 and -31 at the end of the calculations for minutes and seconds respectfully?
    I am not sure exactly, but I know if you change them you will not have the correct time. I am 100% sure that, that would be your problem, but I can't find away around using the extra numbers.

    Maybe you can write an if statement to prevent the negative numbers. Like, if Seconds < 1 Then something or other.


  •  

    Posting Permissions

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