Codice PHP:
<?
function dateControl($dateSes,$dateNow){
$timeLimit = 120;
list($dt1,$tm1) = explode(" ",$dateSes);
list($y1,$m1,$d1) = explode("-",$dt1);
list($h1,$i1,$s1) = explode(":",$tm1);
list($dt2,$tm2) = explode(" ",$dateNow);
list($y2,$m2,$d2) = explode("-",$dt2);
list($h2,$i2,$s2) = explode(":",$tm2);
// int mktime ([ int $hour [, int $minute [, int $second [, int $month [, int $day [, int $year [, int $is_dst ]]]]]]] )
$data1 = mktime($h1,$i1,$s1,$d1,$m1,$y1);
$data2 = mktime($h2,$i2,$s2,$d2,$m2,$y2);
$diff = ($data2-$data1);
if($diff < $timeLimit){
echo "Il tempo minimo di attesa fra un commento e l'altro è di 2 minuti !";
}
}
if (empty($_SESSION['dataora'])) {//se la sessione non esiste...
$_SESSION['dataora'] = date("Y-m-d H:i:s");//la creo con l'attuale orario
//se è stato premuto il tasto d'invio...
if(isset($_POST['insert'])) {
//controllo se è stato scritto l'username.
if($username) {
}else {
$error[] = $msg['empty_username'];
}// fine controllo username.
//controllo se l'email immessa corrisponde sia vaida.
if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
}else {
$error[] = $msg['invalid_email'];
}// fine controllo email.
//controllo se è stato scritto il commento.
if($comment) {
}else {
$error[] = $msg['empty_msg'];
}// fine controllo commento.
//controllo se il codice immesso corrisponde all'imagine.
if (PhpCaptcha::Validate(@$_POST['postcode'])) {
} else {
$error[] = $msg['invalid_code'];
}// fine controllo captcha.
if ($error) {
echo "<h2>ERRORE</h2>";
foreach ($error as $err) {
echo "[*]".$err."";
}
}else {// inserisco i dati nel db.
$query = "INSERT INTO comment (id, pag, nome, email, commento) VALUES ('', '$currentFile', '$username', '$email', '$comment')";
if (!mysql_query($query,$conn)) {
die('Errore: ' . mysql_error());
}
echo "Il Commento è stato aggiunto";
}
}
?>
<form method="post" action="<? $_SERVER['PHP_SELF'] ?>" name="form">
<table width="404" height="263" border="0" cellpadding="1" cellspacing="1">
<tr>
<td height="36" colspan="2">
<input type="text" name="postusername" value="<?=(@$_POST['postusername'])?>">Username
</td>
</tr>
<tr>
<td height="32" colspan="2">
<input type="text" name="postemail" value="<?=(@$_POST['postemail'])?>">Email
</td>
</tr>
<tr>
<td width="226" height="24">
<textarea rows="8" cols="35" name="postcomment" value="" ><?=(@$_POST['postcomment'])?>
</textarea>
</td>
<td width="171">Commento</td>
</tr>
<tr>
<td height="3" colspan="2">
[img]captcha/output.php[/img]</p>
</td>
</tr>
<tr>
<td height="4" colspan="2">
<input type="text" name="postcode">Codice di verifica
</td>
</tr>
<tr>
<td height="11" colspan="2">
<input type="submit" name="insert" value="Invia">
</td>
</tr>
</table>
</form>
<? }
else {
dateControl($_SESSION['dataora'],date("Y-m-d H:i:s"));
}
?>