gazever Posted October 14, 2007 Share Posted October 14, 2007 Really simple question, someone is using my webpage to book villas, they are entering dates as date from, etc. my GET looks like this, availability_booking.php?villa=newvilla1&date_from=2007-12-14 however as input cannot be trusted, I get all villa codes out of sql and put in an array and then check the GET[villa] is inarray before checking the availability. after this I then check for booked dates, id there a simple way of checking to see if the date from day is in the future or not before checking the database, many Thanks Quote Link to comment https://forums.phpfreaks.com/topic/73213-solved-validate-date-input/ Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 try this *untested <?php if ($date($_GET['date_from'])) { echo "valid"; }else{ echo "invalid"; } function validDate($date) { if (preg_match('%((?:19|20)[0-9]{2})[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])%s', $date, $regs)) { return checkdate($regs[2], $regs[3], $regs[1]); } else { return false; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73213-solved-validate-date-input/#findComment-369358 Share on other sites More sharing options...
gazever Posted October 14, 2007 Author Share Posted October 14, 2007 Hi I have a function which supposedly checks if its a valid date or not, Sorry guess I didn't make the original question very clear, What I'm trying to decide is if the date is in the past or not, i.e. yesterday, 3 weeks ago etc. here is my date checking function: function date_checker($date) { $bits_of_date = explode("-", $date); $dd = $bits_of_date[2]; $mm = $bits_of_date[1]; $yy = $bits_of_date[0]; if (is_numeric($yy) && is_numeric($mm) && is_numeric($dd)) { $tocheck = date('Y-n-j', mktime(0, 0, 0, $mm, $dd, $yy)); $tocheck = explode("-", $tocheck); return checkdate($tocheck[1],$tocheck[2],$tocheck[0]); } return false; } Quote Link to comment https://forums.phpfreaks.com/topic/73213-solved-validate-date-input/#findComment-369360 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 <?php if (validDate($_GET['date_from'])) { echo "valid"; }else{ echo "invalid"; } function validDate($date) { if (preg_match('%((?:19|20)[0-9]{2})[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])%s', $date, $reg s)) { if(checkdate($regs[2], $regs[3], $regs[1])) { $tTime = mktime(0, 0, 0, $regs[2], $regs[3], $regs[1]); return ($tTime < time()); } } return false; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73213-solved-validate-date-input/#findComment-369364 Share on other sites More sharing options...
gazever Posted October 14, 2007 Author Share Posted October 14, 2007 Works a treat thanks, Had to change this line of code though return ($tTime < time()); TO: return ($tTime > time()); Quote Link to comment https://forums.phpfreaks.com/topic/73213-solved-validate-date-input/#findComment-369374 Share on other sites More sharing options...
MadTechie Posted October 14, 2007 Share Posted October 14, 2007 LOL, Can you click topic solved please (bottom left) Quote Link to comment https://forums.phpfreaks.com/topic/73213-solved-validate-date-input/#findComment-369378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.