How can PHP be used to verify the age of a user based on inputted date of birth?

To verify the age of a user based on their inputted date of birth, we can calculate the difference between the current date and the user's date of birth, and then check if the user is above a certain age threshold. This can be achieved by using the DateTime class in PHP to handle date calculations.

$userDOB = new DateTime($_POST['dob']);
$today = new DateTime();
$age = $today->diff($userDOB)->y;

if($age >= 18){
    echo "User is above 18 years old.";
} else {
    echo "User is under 18 years old.";
}