drupal 6で、ユーザーが限られた時間(例:10分)でフィールドに入力するように強制できるフォームを作成したいと思います。
この制限時間をコードのサーバー側で処理したいのですが、ユーザーがシステムクロックを変更して時間を変更できるようにしたくありません。
$ _SESSIONなしで可能ですか?
PHP セッションを使用します。このようなものが動作するはずです:
//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
}
}
ユーザーがフォームの操作を開始してからの時間を保存し、送信時に時間が経過したかどうかを確認するのはどうですか?
セッションを使用して、特定のユーザーの時間を保存できます。
これを行うために必要な参照は次のとおりです。
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