Solved

password protecting pages-disable history if session invalid

Posted on 2003-11-15
9
1,210 Views
Last Modified: 2007-12-19
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
Comment
Question by:JennyRo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 11

Expert Comment

by:Zontar
ID: 9757720
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
 
LVL 1

Author Comment

by:JennyRo
ID: 9758073
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
 
LVL 11

Expert Comment

by:Zontar
ID: 9758344
> 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
Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

 

Expert Comment

by:xcab
ID: 9758358
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
 
LVL 1

Author Comment

by:JennyRo
ID: 9759721
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
 
LVL 11

Accepted Solution

by:
Zontar earned 250 total points
ID: 9759881
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
 
LVL 6

Expert Comment

by:DoppyNL
ID: 9762337
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
 
LVL 1

Author Comment

by:JennyRo
ID: 9878871
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
 
LVL 11

Expert Comment

by:Zontar
ID: 9878992
> 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

627 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