note 48671 deleted from function.date by didou
| From: | didou@php.net | Date: | Tue, 04 Jan 2005 14:47:16 +0000 |
| Subject: | note 48671 deleted from function.date by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-82694@lists.php.net to get a copy of this message | ||
Note Submitter: terminal
----
If user enters date from an input field you can easly check it with date and mktime function.
I.E. user enters date in RRRR,MM,DD,hh,mm,ss format in single input field.
<?php
// Var init
$error = 0;
// Form data
$time = trim($_POST['time']);
// Code
list ($Y,$m,$d,$H,$i,$s) = explode (',', $time, 6);
// Following checks can be more robust
empty($Y) ? $error = 1 : 0;
empty($m) ? $error = 1 : 0;
empty($d) ? $error = 1 : 0;
empty($H) ? $error = 1 : 0;
empty($i) ? $error = 1 : 0;
empty($s) ? $error = 1 : 0;
// If date is say 2004,02,31,00,00,00 it will trigger error. (read mktime doc)
$time2 = date ("Y,m,d,H,i,s", mktime($H,$i,$s,$m,$d,$Y));
($time != $time2) ? $error = 1 : 0;
($error) ? echo "BAD" : echo "Good";
?>
----
Reason: bad code