date of birth confirmation (+better validation) in php

0
103
date of birth confirmation
date of birth confirmation

verifying if given date of birth is permitted in a logical restriction using php
Hey there have you tried to add age restriction in your web application

Cool!

that’s nice to wave off some underage or overage from participating your services
You just need a range of age.

You only want user’s date of birth with in the range specified.

Need for Birthday Confirmation

Sometimes you may want to throw birthday message to user when they visit your web application
you may consider writting a logic in php by stating if the current date is same as the user date of birth

Alright you might be seeing some different or something similar or simpler your suggested logic

So far we have validated date and used formless date inputs (bootstrap no form control)

you may try it out

well nevertheless let’s start

the user date of birth used for this project is 1975-02-23

let us validate the date of birth first

 <?php 
$thedob = '1975-02-23'; //this is the date being checked
$thedob = explode('-', $thedob);
$year_dob = $thedob[0];
$month_dob = $thedob[1];
$day_dob = $thedob[2];

//since it a bool we are using logic to output it result
if(!checkdate($month_dob, $day_dob, $year_dob)){
	echo 'The date of birth is Invalid : Hey! pls. Retreat';
}else{
	echo 'The date of birth is Valid : Continue my friend';
}

?>

Using the birthday validation

decide birthday wish day

let’s wish the user happy birthday if the user date of birth matches the current day and month match

hope you know birthday is compared using month and day excluding year

since the date of birth is 1975-02-23 we will compare 02-23(february 23rd) with the current month and day

 <?php 
$thedob = '1975-02-23'; //this is the date being checked
$thedob = explode('-', $thedob);
$year_dob = $thedob[0];
$month_dob = $thedob[1];
$day_dob = $thedob[2];

//since it a bool we are using logic to output it result
if(!checkdate($month_dob, $day_dob, $year_dob)){
	echo 'The date of birth is Invalid : Hey! pls. Retreat';
}else{
	//THE BIRTHDAY WISH
	if(date('m-d') == ($month_dob.'-'.$day_dob)){
		echo 'Hey Happy Birthday: it is a valid date of birthday';
	}else{
		echo 'Today is not your birthday. The date of birth is Valid : Continue my friend';
	}
}

?>

Now it is time to run our test if you are on localhost just reset your local machine date and time to match date of birth month and used in this project

Oh! less i forgot remeber to reset back your computer local machine time back to your up to date current time

Check your watch or mobile phone for current time and date if you’ve forgotten.

LEAVE A REPLY

Please enter your comment!
Please enter your name here