Having a bit of trouble with an Age Verification Script I pieced together from a few sources. I have a site where regardless of the page or directory the user initially enters on, each page will check for the existence of a cookie and if it does not exist, will redirect them to a verify.php page. From there the user will enter in their date of birth and if the total seconds = greater than 21 years old, the cookie is created and the user is sent back to the page that they entered on. If they are not 21, they get sent to google.com. The issue I am having is that regardless of what they enter, they are being sent to google.com.
Here is the bit of PHP at the top of each page...
<?php
function over21(){
$redirect_url='/verify.php';
$expires=-1;
session_start();
$validated=false;
if(!empty($_COOKIE["over21"])) { $validated=true; }
if(!$validated && isset($_SESSION['over21'])) { $validated=true; }
if(is_numeric($expires) && $expires==-1 && !isset($_SESSION['over21'])) { $validated=false; }
if($validated) { return; }
else {
$redirect_url=$redirect_url."?return=".$_SERVER['REQUEST_URI']."&x=".$expires;
Header('Location: '.$redirect_url);
exit(0);
}
}
over21();
?>
And here is the verify.php file
<?php
session_start();
if($_SERVER['REQUEST_METHOD']=='POST')
{
if(isset($_SESSION['over21']))
{
$redirect=isset($_GET['return'])?urldecode($_GET['return']):'./';
$expire=isset($_GET['x']) && is_numeric($_GET['x'])?intval($_GET['x']):-1;
if($expire==-1)
{
setcookie("verified", "yes", "over21", mktime(0,0,0,01,01,date("Y")+30));
$_SESSION['verified']="yes";
header("location: ".$redirect);
exit(0);
}
}
if(isset($_SESSION['under21']))
{
header("location: http://google.com");
}
if(isset($_POST['submit']))
{
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$birthday = mktime(0,0,0,$month,$day,$year);
$difference = time() - $birthday;
$age = floor($difference / 662256000);
if($age >= 21)
{
setcookie("verified", "yes", "over21", mktime(0,0,0,01,01,date("Y")+30));
$_SESSION['over21'] = 1;
header("location: ".$redirect);
}
else
{
$_SESSION['under21'] = 0;
header("location: http://google.com");
}
}
}
?>
<html>
<form action="" method="POST">
Day: <select name="day">
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
<option>06</option>
<option>07</option>
<option>08</option>
<option>09</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
Month:<select name="month">
<option value="01">Jan</option>
<option value="02">Feb</option>
<option value="03">Mar</option>
<option value="04">Apr</option>
<option value="05">May</option>
<option value="06">Jun</option>
<option value="07">Jul</option>
<option value="08">Aug</option>
<option value="09">Sept</option>
<option value="10">Oct</option>
<option value="11">Nov</option>
<option value="12">Dec</option>
</select>
Year: <select name="year">
<option>1990</option>
<option>1991</option>
<option>1992</option>
<option>1993</option>
<option>1994</option>
<option>1995</option>
<option>1996</option>
<option>1997</option>
<option>1998</option>
<option>1999</option>
<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
<option>2007</option>
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
</select>
<input type="submit" value="Enter" name="submit">
</form>
</html>
I am clearly a PHP newb so I appreciate any pointers on syntax as well as how to get this thing to actually work.
Thanks!
Gregg

New Topic/Question
Reply



MultiQuote







|