Jump to content

Age verification


kingkhan

Recommended Posts

Hello everyone,

 

Im really weak at coding in PHP and have come across a problem..here goes

 

I have a drinks website, the startup page is a php page which enables users to choose country and year of birth, which is coded so that if the users year of birth is equal to 18 or over then upon submitting enables them to view the full website...otherwise produces a page with drinksaware links and tells them that they are too young to view the website..(the website wants to be responsible,therefore this method is being undertaken.)

 

at the moment everything works as it should, however i have come across the obvious problem of age limits in certain countries i.e. 21 years in states, 19 in canada etc..

 

how can i get the code to accept 18 or over in UK, but only accept 21 or over in states and 19 or over in Canada?

 

have no idea how to do this!! please can somebody help me.....

 

heres is the code i am using for the php part

 

if(isset($_POST['submit']))
{
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$agelimit = $_POST['country'];

$birthday = mktime(0,0,0,$month,$day,$year);
$difference = time() - $birthday;
$age = floor ($difference / 31556926);

if($age >= 18)
{
	$_SESSION['over18'] = 1;
	header("location: index.html");
}
else
{
	$_SESSION['under18'] = 0;
	header("location: leave.php");
}
}

?>

 

here is the code i am using for the form

<form id="verification" action="index.php" method="post">
<table width="300" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td height="100"></td>
  </tr>
</table>

<table width="161" border="0" cellspacing="0" cellpadding="0" align="center" height="203">
  <tr>
    <td><img src="images/logo.png" width="161" height="163" /></td>
  </tr>
</table>

<table width="500" border="0" cellspacing="0" cellpadding="0" align="center" height="100">
  <tr>
    <td align="center" style="color:#9A9A9A; font-size:14px;">One of our key missions is to ensure that our drinks are enjoyed responsibly. We must confirm that you are of legal drinking age in your country before welcoming you to LF Brut.  If there is no legal age for consuming alcohol in your country, you must be over 21.</td>
  </tr>
</table>

<table width="350" border="0" cellspacing="15" cellpadding="0" align="center">
  <tr>
    <td width="300" align="right" style="color:#9A9A9A; text-transform:uppercase; font-size:12px;"><label class="listLabel" for="country"><strong>Country</strong></label></td>
    <td width="50">
    <div class="styled-select">
    <select id="country" name="country" class="select">
<optgroup label="RECENT">
<option value="1">Australia</option>
<option value="3">Belgium</option>
<option value="4">Brazil</option>
<option value="6">China</option>
<option value="9">France</option>
<option value="10">Germany</option>
<option value="15">Ireland</option>
<option value="17">Italy</option>
<option value="18">Japan</option>
<option value="20">Mexico</option>
<option value="30">Spain</option>
<option selected="selected" value="34">United Kingdom</option>
<option value="35">United States</option>
</optgroup>
<optgroup label="ALL COUNTRIES">
<option value="1">Australia</option>
<option value="2">Austria</option>
<option value="3">Belgium</option>
<option value="4">Brazil</option>
<option value="5">Canada</option>
<option value="6">China</option>
<option value="7">Denmark</option>
<option value="8">Finland</option>
<option value="9">France</option>
<option value="10">Germany</option>
<option value="11">Greece</option>
<option value="12">Hungary</option>
<option value="13">India</option>
<option value="14">Indonesia</option>
<option value="15">Ireland</option>
<option value="16">Israel</option>
<option value="17">Italy</option>
<option value="18">Japan</option>
<option value="19">Malaysia</option>
<option value="20">Mexico</option>
<option value="21">Netherlands</option>
<option value="22">New Zealand</option>
<option value="23">Nigeria</option>
<option value="24">Norway</option>
<option value="36">Other countries</option>
<option value="25">Poland</option>
<option value="26">Portugal</option>
<option value="27">Russia</option>
<option value="28">Singapore</option>
<option value="29">South Africa</option>
<option value="30">Spain</option>
<option value="31">Sweden</option>
<option value="32">Switzerland</option>
<option value="33">United Arab Emirates</option>
<option selected="selected" value="34">United Kingdom</option>
<option value="35">United States</option>
</optgroup>
</select></div>

  	</td>
  </tr>
  <tr>
    <td width="300" align="right" style="color:#9A9A9A; text-transform:uppercase; font-size:12px;"><label class="listLabel" for="birthdate"><strong>Date of birth</strong></label></td>
    <td width="50">
<select id="year" name="year">
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
<option value="1989">1989</option>
<option value="1988">1988</option>
<option value="1987">1987</option>
<option value="1986">1986</option>
<option value="1985">1985</option>
<option selected="selected" value="1984">1984</option>
<option value="1983">1983</option>
<option value="1982">1982</option>
<option value="1981">1981</option>
<option value="1980">1980</option>
<option value="1979">1979</option>
<option value="1978">1978</option>
<option value="1977">1977</option>
<option value="1976">1976</option>
<option value="1975">1975</option>
<option value="1974">1974</option>
<option value="1973">1973</option>
<option value="1972">1972</option>
<option value="1971">1971</option>
<option value="1970">1970</option>
<option value="1969">1969</option>
<option value="1968">1968</option>
<option value="1967">1967</option>
<option value="1966">1966</option>
<option value="1965">1965</option>
<option value="1964">1964</option>
<option value="1963">1963</option>
<option value="1962">1962</option>
<option value="1961">1961</option>
<option value="1960">1960</option>
<option value="1959">1959</option>
<option value="1958">1958</option>
<option value="1957">1957</option>
<option value="1956">1956</option>
<option value="1955">1955</option>
<option value="1954">1954</option>
<option value="1953">1953</option>
<option value="1952">1952</option>
<option value="1951">1951</option>
<option value="1950">1950</option>
<option value="1949">1949</option>
<option value="1948">1948</option>
<option value="1947">1947</option>
<option value="1946">1946</option>
<option value="1945">1945</option>
<option value="1944">1944</option>
<option value="1943">1943</option>
<option value="1942">1942</option>
<option value="1941">1941</option>
<option value="1940">1940</option>
<option value="1939">1939</option>
<option value="1938">1938</option>
<option value="1937">1937</option>
<option value="1936">1936</option>
<option value="1935">1935</option>
<option value="1934">1934</option>
<option value="1933">1933</option>
<option value="1932">1932</option>
<option value="1931">1931</option>
<option value="1930">1930</option>
<option value="1929">1929</option>
<option value="1928">1928</option>
<option value="1927">1927</option>
<option value="1926">1926</option>
<option value="1925">1925</option>
<option value="1924">1924</option>
<option value="1923">1923</option>
<option value="1922">1922</option>
<option value="1921">1921</option>
<option value="1920">1920</option>
<option value="1919">1919</option>
<option value="1918">1918</option>
<option value="1917">1917</option>
<option value="1916">1916</option>
<option value="1915">1915</option>
<option value="1914">1914</option>
<option value="1913">1913</option>
<option value="1912">1912</option>
<option value="1911">1911</option>
<option value="1910">1910</option>
<option value="1909">1909</option>
<option value="1908">1908</option>
<option value="1907">1907</option>
<option value="1906">1906</option>
<option value="1905">1905</option>
<option value="1904">1904</option>
<option value="1903">1903</option>
<option value="1902">1902</option>
<option value="1901">1901</option>
<option value="1900">1900</option>
<option value="1899">1899</option>
<option value="1898">1898</option>
<option value="1897">1897</option>
<option value="1896">1896</option>
<option value="1895">1895</option>
<option value="1894">1894</option>
</select></td>
  </tr>
  
  <tr>
  <td colspan="2" align="center">
    <button name="submit" id="submit" style="background-image:url(images/enter.png); background-color:transparent; border:none; width:48px; height:15px; cursor:pointer;"></button>
    
  <input type="hidden" value="01" name="day" id="day" />
  <input type="hidden" value="01" name="month" id="month"/>
  </td>
  </tr>
  <tr>
  <td height="80"></td>
  <td height="80"></td>
  </tr>
</table>
<table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td align="center" style="font-size:12px; color:#5A5A5A;">DRINK RESPONSIBLY. We support the responsible consumption of wines and spirits, through LF Brut, member of the European Forum for Responsible Drinking (<a href="http://www.efrd.org" target="_blank">www.efrd.org</a>) and DISCUS (<a href="http://www.discus.org" target="_blank">www.discus.org</a>), CEEV (<a href="http://www.wineinmoderation.eu" target="_blank">www.wineinmoderation.eu</a>) and Entreprise et Prévention (<a href="http://www.soifdevivre.com" target="_blank">www.soifdevivre.com</a>).</td>
  </tr>
</table>

<table width="500" border="0" cellspacing="0" cellpadding="0" align="center" height="50">
  <tr>
    <td align="center" style="font-size:12px; color:#9A9A9A;">By entering this site you acknowledge that you accept its terms and conditions of use
THE ABUSE OF ALCOHOL IS DANGEROUS FOR YOUR HEALTH</td>
  </tr>
</table>


</form>

 

 

Link to comment
Share on other sites

First I would recommend assigning country to a variable named $country:

 

<?php
$country = $_POST['country'];
?>

 

 

Then figure out the age limit based on the country value. For example

 

<?php
switch($country) {
    case 35: $agelimit=21; break; //United States
    case 5:  $agelimit=18; break; //Canada
    ...
}
?>

 

 

Then just modify the age limit test:

 

<?php
if($age >= $agelimit)
?>

 

 

 

Note: the switch() part of the above code would be dependent on how the age limit data stored. If it's stored in a database, you could run a query instead of using switch().

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.