Link to home
Start Free TrialLog in
Avatar of JennyRo
JennyRo

asked on

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
Avatar of Zontar
Zontar

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.
Avatar of JennyRo

ASKER

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

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
Avatar of JennyRo

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Zontar
Zontar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of JennyRo

ASKER

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