• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

Pop-up Alert Before Session Ends

Hi all.

I have a shopping cart which relies on Session Arrays to hold the item numbers/prices of items added to the cart.  After processing I use this array to present download links to the customer to deleiver their product  

Problem:  If a user keeps their browser window open for more than the session length (which is already extra-ordinarily long!) Their cc gets processed but the item numbers are not transferred so that they can download the selected products.

What is the easiest/best way to fix this?  Is there some way that I can pop-up an alert about 2 minutes before the session is about to end so that they know they need to do something to maintain the session state???

Thanks for all your ideas.
0
ClassyLinks
Asked:
ClassyLinks
  • 3
  • 2
  • 2
  • +3
1 Solution
 
rupertsCommented:
A lot of online testing sites have this feature, if you leave a question on a webpage open for 5 minutes say, then a javascript alert box comes up and reminds the user that they have 1 minute to click on the answer before the session terminates.

As an alternative solution why not use cookies to store the information on the client and set the expiry date to some time in the future.

(If you like either I can post code)
0
 
ClassyLinksAuthor Commented:
Hi ruperts.

I've got a javascript code that times people on a particular page....but I don't know how to use it for the SESSION, not just one particular page.

Your code would be appreciated.
0
 
rupertsCommented:
Thinking about it..

Cookies are definately the way forward...

Replace
session("valueX") = 2
session("valueY") = 3

With
Response.Cookies("MYCart")("valueX") = 2
Response.Cookies("MYCart")("valueY") = 3
Response.Cookies("MYCart").Expires = Date() + 1

And

dim localVarX,localVarY
Replace
localVarX = session("valueX")
localVarY = session("valueY")
With
localVarX = request.Cookies("MYCart")("valueX")
localVarY = request.Cookies("MYCart")("valueY")


0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ClassyLinksAuthor Commented:
You may have lost me, but I'll take a look at it and see if I can understand what you're saying.

Have to run to a meeting back later in the day.

Thanks!
0
 
vindevogelCommented:
When the session times out, the first click by the user will reopen a session.  In there, you can check what page is shown ...

If you don't like that page (because they're in the middle of your site, and they've lost connection)  you can redirect them.  I post the code below.

We do that in the global.asa.

Same thing you can do on a Session_OnEnd
Write away what the user needs to store into a cookie, also by redirecting him.



Sub Session_OnStart
     'Make sure that new users start on the correct page of the ASP application
     Const csStartPage = "/user.asp"
     Const csLoginPage = "/Login.asp"
     Const csIndexPage = "/index.asp"
     Const csReStartPage = "/SessionEnd.asp"
     Dim sCurrentPage

                    'This replaces the following code in the beginning of EVERY ASP-page
                    'If Session("User") = "" Then
                    '     Response.Redirect "http://" & Request.ServerVariables("SERVER_NAME") & ":" & _
                    '                       Request.ServerVariables("SERVER_PORT") & "/SessionEnd.asp"
                    'Else
                    ' ... code ...
                    'End If
     sCurrentPage = Request.ServerVariables("SCRIPT_NAME")
     
    If not((strcomp(sCurrentPage, csStartPage, 1) = 0) OR _
           (strcomp(sCurrentPage, csIndexPage, 1) = 0) OR _
           (strcomp(sCurrentPage, csLoginPage, 1) = 0)) Then
          Response.Redirect "http://" & Request.ServerVariables("SERVER_NAME") & ":" & _
                            Request.ServerVariables("SERVER_PORT") & csReStartPage
     End If
End Sub
0
 
brunoCommented:
Classy,

this is a kind of silly solution, and sort of overrides the use of sessions, but say your session is 20 minutes long, just put a meta refresh on that page only at 18 minutes, to have the page refresh to itself.


BRUNO
0
 
mgfranzCommented:
I haven't seen anyone mention the JavaScript setTimeOut() method;

<script language="javascript">
function displayAlert()
{
alert("Your Session will time out in 1 minute!")
}
</script>
<!-- Set the timeout to run at 19 minutes -->
<body onLoad="setTimeout('displayAlert()',1140000)">

This assumes the session is set to 20 minutes...
0
 
manihopeverCommented:
Dear CLs,

Why dont you have a session called "StartsAT" and with this subtract your hours and fire an alert if its few minutes more to expire.  

1. Create a session for storing users login start time.
    ex: Session("StartsAT") = Date() &" "& time()
2. You have mentioned the Timeout right?.  get the timeout
   value and use datediff.
    ex:
    <% strStartsAT = Session("StartsAT")
       strTimeout  = Session.Timeout
       Minutesdiff = datediff("n",strStartsAT, strTimeout)  'for minutes
       if Minutesdiff<=2 then %>
       <script language=javascript>
          alert("2 minutes more to expire..!")
       </script>
    <%end if%>  

disadvantage:
   it only fires at the time of opening each page.  Instead if you using javascript codes using SetTimeOut.  You can get the alert box in live.  That is eventhough you are doing something in a page, you will precautioned with the alert box.  so in this case, mgfranz solutions is right.
0
 
ClassyLinksAuthor Commented:
Hi all.

Thanks for all the suggestions.

I have investiagted all the options and am going to go with the JavaScript.

I need something that works not only on the load of the page, but when they've had it open for too long.  The meta refresh option, while intriguing, didn't work because often they are coming from a form page (adding to the cart) and would therefore reprocess the form and add duplicate items to the cart.

Thanks!
0
 
mgfranzCommented:
Thank you!
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now