Solved

Pop-up Alert Before Session Ends

Posted on 2002-03-19
10
554 Views
Last Modified: 2008-02-26
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
Comment
Question by:ClassyLinks
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 4

Expert Comment

by:ruperts
ID: 6879801
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
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6879830
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
 
LVL 4

Expert Comment

by:ruperts
ID: 6879882
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
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6879923
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
 
LVL 4

Expert Comment

by:vindevogel
ID: 6880528
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 18

Expert Comment

by:bruno
ID: 6880756
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
 
LVL 18

Accepted Solution

by:
mgfranz earned 50 total points
ID: 6881561
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
 
LVL 2

Expert Comment

by:manihopever
ID: 6890684
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
 
LVL 7

Author Comment

by:ClassyLinks
ID: 6892154
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
 
LVL 18

Expert Comment

by:mgfranz
ID: 6892158
Thank you!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now