Solved

Pop-up Alert Before Session Ends

Posted on 2002-03-19
10
556 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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
 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

778 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