|
|
|
|
|
|
| |
This example includes a function, old_enough_check(), that checks a date of birth that is passed to it and returns TRUE or FALSE if the person's age is between a minumum and maximum value (i.e. between 18 and 100 years old).
| <?php
/*
Description: Old Enough Check
Author: Murray Moffatt for A Web 4 U Designs
History:
2004-02-04 : Initial coding.
2005-02-17 : Make stand-alone and include sample form for
publishing on WeberDev.com.
*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Old Enough Check</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<h3>Old Enough Check</h3>
<?php
$step = $_POST["step"];
if ($step == "") {
?>
<p>To access this site you must be at least 18 years old.</p>
<p>Please enter your birth date:</p>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" name="dobForm">
<table border="0" cellspacing="1" cellpadding="2">
<tr>
<td align="right">Date of Birth:</td>
<td align="left"><input name="dob" type="text" size="10" maxlength="10"> (MM/DD/YYYY)</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Check Age">
<input name="step" type="hidden" value="1">
</td>
</tr>
</table>
</form>
<?php
}
if ($step == "1") {
$dob = $_POST["dob"];
list($month, $day, $year) = explode("/", $dob);
if (!old_enough_check($month, $day, $year)) {
echo "<p>Sorry, you are not permitted to access this site</p>";
} else {
echo "<p>Come on in!</p>";
}
}
function old_enough_check($month = 0, $day = 0, $year = 0) {
define(MINIMUM_AGE, 18); // Youngest age we'll accept
define(MAXIMUM_AGE, 100); // Oldest age we'll accept
// Throw out any bad dates
if (!checkdate($month, $day, $year)) {
return FALSE;
}
// Get the current date
list($current_year, $current_month, $current_day) = explode(",", date("Y,m,d"));
// Check that the date of birth falls between the youngest and oldest ages that we'll accept
$min_year = $current_year - MAXIMUM_AGE;
$max_year = $current_year - MINIMUM_AGE;
if (($year > $min_year) and ($year < $max_year)) {
return TRUE;
} elseif (($year == $max_year) and (($month < $current_month) or (($month == $current_month) and ($day <= $current_day)))) {
return TRUE;
} elseif (($year == $min_year) and (($month > $current_month) or (($month == $current_month and ($day > $current_day))))) {
return TRUE;
} else {
return FALSE;
}
}
?>
</body>
</html> | | |
|
| A Timing Class Categories : PHP, PHP Classes, Date Time | | | Finding the day of the week for a specific date.
Categories : PHP, Databases, MySQL, Date Time | | | A wrapper function to format dates coming from a databases with the
same syntax as PHP's date() function. Categories : Date Time, Databases, PHP | | | pcCalendar class - Allows for the creation of calendars in HTML pages. All output functions can be easily overridden, refer to article 1471 for an example.
Categories : PHP, Date Time, Calendar, PHP Classes | | | A PHP Calendar function with CSS : add a cool calendar to any php page by just adding a calendar class based function. Categories : PHP, PHP Classes, Calendar, Date Time | | | PHP Round Clock - Must have Gif support to use this. Categories : PHP, Date Time, Graphics | | | A simple and fast calendar combining PHP and tables. Use this as a base for applications in which a calendar is needed. Categories : Date Time, PHP, Complete Programs, Calendar | | | Open and Close your website in fixed times . Categories : PHP, PHP Classes, Cron, Date Time | | | mysql date/time converters Categories : PHP, MySQL, Databases, Date Time | | | Creates three SELECT form fields: Month, Day, and Year. You give it a string which will be used to make the name for the three fields, and a number of seconds to use as the default date. If you give it blank for this value, the current date is used. Categories : HTML and PHP, PHP, Date Time | | | If you want to create select buttons featuring current date this example will show you how... Categories : Date Time, HTML and PHP, PHP | | | Example of using the pcCalendar class, article 1468 on weberdev.com. Calendar example. Categories : PHP, Date Time, PHP Classes, Calendar | | | calculus of the eastersunday Categories : BC math, PHP, Date Time, Databases | | | Functions used to define a schedule of holidays. Can define non-fixed holidays (eg. 3rd sunday of June). Categories : Calendar, Date Time, PHP | | | Monthly and Daily Upcoming Events calendar. Categories : Date Time, PostgreSQL, PHP, Calendar, Databases | |
|
|
|