...

View Full Version : code for how to restrict refresh page for online exam in javasript



prachippp
03-19-2012, 01:58 PM
i want to restrict refresh option for online examination can any one give me solution as early as possible .....please

I have written below script for timer

when i refresh the page timer is reset again.

<script type="text/javascript">
var settimmer = 0;
$(function(){
window.setInterval(function() {
var timeCounter = $("b[id=show-time]").html();
var updateTime = eval(timeCounter)- eval(1);
$("b[id=show-time]").html(updateTime);

if(updateTime == 0){
$("div[id=my-timer]").html("").html("Page redirecting........");
window.location = ("welcome.php");
}
}, 1000);

});
</script>

// Body Part
<div id="my-timer">

Page Will Redirect with in <b id="show-time">1800</b> seconds
</div>



Thank You ...!

Philip M
03-19-2012, 02:03 PM
i want to restrict refresh option for online examination can any one give me solution as early as possible .....please



You can't. If the user presses F5 the page will refresh. You should use server-side coding to stop the timer resetting.

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

rnd me
03-20-2012, 01:20 AM
replace

var timeCounter = $("b[id=show-time]").html();

with

var timeCounter = localStorage.dt || $("b[id=show-time]").html();




and

$("b[id=show-time]").html(updateTime);


with

$("b[id=show-time]").html(localStorage.dt=updateTime);




to reset the clock, somehow call:

localStorage.dt="";





OT:

eval(1); lol

felgall
03-20-2012, 01:59 AM
Note that not all browsers that people currently use support localStorage - it would be safer at the moment to use a cookie instead.

Philip M
03-20-2012, 08:28 AM
Note that not all browsers that people currently use support localStorage - it would be safer at the moment to use a cookie instead.

But the user can delete the cookie! That is hardly secure for an examination.

felgall
03-20-2012, 08:34 AM
But the user can delete the cookie! That is hardly secure for an examination.

The user can turn off JavaScript completely as well if they want to. There is no client side solution that is all that secure.

Any decent security would have to be built using a server side script. and even that would need to use a session cookie to track the person - and the person could potentially delete that cookie just as they could if the cookie was set using JavaScript. The only difference would be that all the cookie would contain is a session id and everything else would be saved on the server using the session id to identify the person.

The only way around them being able to delete the cookie is to fail anyone who deletes the cookie.

Philip M
03-20-2012, 09:04 AM
The user can turn off JavaScript completely as well if they want to. There is no client side solution that is all that secure.

Any decent security would have to be built using a server side script. and even that would need to use a session cookie to track the person - and the person could potentially delete that cookie just as they could if the cookie was set using JavaScript. The only difference would be that all the cookie would contain is a session id and everything else would be saved on the server using the session id to identify the person.

The only way around them being able to delete the cookie is to fail anyone who deletes the cookie.

How will you know that they have deleted the cookie? A new cookie and new session id will be generated.

webdev1958
03-20-2012, 09:42 AM
i want to restrict refresh option for online examination can any one give me solution as early as possible .....please



If this is for a real world application are you really, really sure you want to do this with javascript? The only totally secure way to do this without leaving the exam process vulnerable is to do it server side.

What do you want to stop from happening if the user refreshes the web page?

Philip M
03-20-2012, 01:50 PM
If this is for a real world application are you really, really sure you want to do this with javascript? The only totally secure way to do this without leaving the exam process vulnerable is to do it server side.

What do you want to stop from happening if the user refreshes the web page?

See post#2. Re-starting the timer, of course.

webdev1958
03-20-2012, 01:56 PM
See post#2. Re-starting the timer, of course.

There are a lot more security issues to consider than just the timer :)

If the op replies to my question then maybe I'll be able to help more :thumbsup:

felgall
03-20-2012, 07:15 PM
How will you know that they have deleted the cookie? A new cookie and new session id will be generated.

You would then have two entries on the server with the same name attached - one for each of the cookies.

You just need it set up so that the server side data the cookie refers to doesn't get deleted until after the exam has been marked. Deleting the cookie would just remove the person's ability to complete that particular exam.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum