Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1221
  • Last Modified:

password protecting pages-disable history if session invalid

I have a site using MS Access, ASP, and Javascript, which serves web pages from the database dependent on certain conditions.

My question concerns the administration side of the site. (The database is only accessed by the administrators - not viewers of site)

When the administrators want to edit their web pages they have to enter a password which allows them access to various parts of the site dependent on the level of access they have which is stored in a session variable.

What I want is to make sure that when their session is ended (after the default 20min), some other staff member can't hit the back button and access their pages.

I had a solution, but this involved not allowing any history access at all, whereas I want them to be able to access the history only if their session is not yet finished.

Cheers
Jenny
0
JennyRo
Asked:
JennyRo
1 Solution
 
ZontarCommented:
The only control you have over a user's browser history (as such) is the user of the location.replace() method, which substitutes a new page for the current one in the browser history.

You can use the following HTML tags to suppress caching:

<meta http-equiv="Content-Expires" content="Tue, 01 Jan 1980 12:00:00 GMT">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">

These are not 100% guaranteed to work in all browsers -- they're only "suggestions" and not "commands".

You should check the login session before peforming any other action on any of the admin pages -- you can't prevent someone from using the Back button to view pages from the history with 100% certainty, but you can certainly prevent them from taking any action once the session has been ended.
0
 
JennyRoAuthor Commented:
If I have a page which checks the session variable, how do I then send them back to their page with all their entries still there?

I tried javascript:window.history.forward(1); but this didn't seem to work - am I way off base here?

I also tried having a layer with the login form on it, and then responding to it in the same page the user is working on, but I had all sorts of problems here so I would prefer something involving a separate page.

Thanks
Jenny
0
 
ZontarCommented:
> If I have a page which checks the session variable, how do I then send them back to their page with all their entries still there?

You're trying to do it backwards -- write an include that checks the login status and redirects to a login page if they're not logged in. Put in the include at the very top of each page.

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
xcabCommented:
Though a little cumbersome, if this functionality is really that important I would do the following:

(1) Give each page a unique id
(2) When leaving each page, write a cookie that references the unique page id
(3) When loading each page, check for the existence of a cookie with that page's id. If it exists, load the data.

This page nicely explains it all:

http://codepunk.hardwar.org.uk/ajs27.htm
0
 
JennyRoAuthor Commented:
Why this is important is because there is alot of info that is being entered at any one time - a whole web page worth pretty much.

So if the session has expired I don't want them to lose all their data by being taken off to a different page to log in again.

Zontar - how would I get them back from the login page without losing their data - there is my problem.

I thought this would work->(javascript:window.history.forward(1);) - but it doesn't seem to

Cheers
Jenny
0
 
ZontarCommented:
You could always increase the length of the session timeout (believe you'd do this in the global.asa if memory serves correctly) -- or use a cookie that lasts until the user logs out or shuts down the browser.

history.forward() takes the user forward in the browsing history, what you want maybe would be

history.back();

or

history.go(-1);

to go back one page in the browsing history.

If you're using a link's href attribute then you need the javascript: protocol; if you're using an event handler, it's not required:

<a href="javascript:history.back();"></a>
<input type="button" onclick="history.go(-1);">

To redirect from a serverside script, you'd use something like

If [session is valid] Then
  Response.Write "<script type=""text/javascript"">history.back();</script>"
Else
  Response.Write "<p>Invalid Login -- please try again.</p>"
End If

or

If [session is valid] Then
  Response.Redirect Request.ServerVariables("HTTP_REFERER")
Else
  Response.Write "<p>Invalid Login -- please try again.</p>"
End If

You might need to store the referring URL in a session or querystring variable.

Does that help at all?
0
 
DoppyNLCommented:
Simply make sure the session is destroyed when the user is logged out.
Also instruct your administrators that they must close ALL browsers when the log out and leave their computer; this will result in all pages be requested again (or at least ask the server if they've been updated). They are admins so they will know what they are doing. (otherwise I wouldn't make them an admin!)

Also check on every page if the user is logged in or not.

If you've done all this, then it won't be possible to see pages in your history that the person is not allowed to see.
0
 
JennyRoAuthor Commented:
That was pretty silly me getting that forward and back stuff muddled up.

I would like to know what this does in reference to my problem though:  
Response.Redirect Request.ServerVariables("HTTP_REFERER")

I haven't used ServerVariables except in a form validation sense.

I assumed it just redirected the page to the last page but it didn't seem to do anything

Cheers
Jenny
0
 
ZontarCommented:
> I assumed it just redirected the page to the last page but it didn't seem to do anything

It should, but if you just load the page directly and haven't followed a link, then Request.ServerVariables("HTTP_REFERER") is empty.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now