Reputation: 496
I want to create a form in drupal 6 that user has force to fill the fields in a limited time (eg: 10 min).
I want to handle this limit time in the server side of my code.I don't want the user can change the time by change it's system clock.
Is it possible without $_SESSION ?
Upvotes: 0
Views: 87
Reputation: 365
How about storing a time from when the user starts interacting with the form, and checking if the time has passed upon submission?
You can store the time for the specific user using sessions.
These are the references you need to do this:
http://php.net/manual/en/function.session-start.php
http://se2.php.net/manual/en/function.date.php
http://se2.php.net/manual/en/function.date-diff.php
Upvotes: 1
Reputation: 5374
Use a PHP session. Something like this should work:
//Set your start time when the user enters the page:
session_start();
if(!isset($_SESSION['start_time'])){
$_SESSION['start_time'] = time();
}
//Check the current time against the start time when the user submits:
if(!isset($_SESSION['start_time'])){
$elapsed = time() - $_SESSION['start_time'];
$limit = 10*60; //Since time() is in seconds, multiply desired # of minutes by 60
if($elapsed <= $limit){
//It took less than 10 minutes
}else{
//It took more than 10 minutes
}
}
Upvotes: 1