Age verifcation on Index page for adult site... like pornotube.com

Discussion in 'PHP' started by Alvin, Nov 26, 2006.

  1. #1
    Hello friends,

    I am looking for a script or code to put it on a index page of adult site that asks for visitors age.

    I dont want this in HTML so that user has to go thru this every time.. i want it to
    set a cookie if user has already entered his/her age... once he dont have to do it again..


    Very good example of this is Pornotube.com

    can anyone help me with this please
     
    Alvin, Nov 26, 2006 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    <?php
    
    $verified = false;
    
    if ($_POST['verify'])
    {
    	extract(array_map('intval', $_POST));
    	
    	if (!checkdate($month, $day, $year))
    	{
    		exit('Invalid birthday.');
    	}
    	
    	$now = mktime(0, 0, 0);
    	$birthday = mktime(0, 0, 0, $month, $day, $year);
    	$age = intval(($now - $birthday) / (3600 * 24 * 365));
    
    	if ($age >= 18)
    	{
    		setcookie('age_verified', 1, time()+3600*24*7, '/');
    		$verified = true;
    	}
    	else
    	{
    		echo 'Sorry, you are too young.';
    	}
    }
    
    
    ?>
    
    <?php
    
    if (isset($_COOKIE['age_verified']) OR $verified)
    {
    	// Page content
    }
    else
    {
    ?>
    <form action="" method="post">
    <select name="day">
    <option>Day</option>
    
    <?php
    	
    for ($day = 1; $day <= 31; $day++)
    {
    	echo "\t". '<option value="'. $day .'">'. $day ."</option>\n";
    }
    ?>
    </select>
    
    <select name="month">
    <option>Month</option>
    
    <?php
    	
    for ($month = 1; $month <= 12; $month++)
    {
    	echo "\t". '<option value="'. $month .'">'. $month ."</option>\n";
    }
    ?>
    </select>
    
    
    <select name="year">
    <option>Year</option>
    <?php
    	
    for ($year = date('Y')-80; $year <= date('Y'); $year++)
    {
    	echo "\t". '<option value="'. $year .'">'. $year ."</option>\n";
    }
    ?>
    </select>
    
    <input type="submit" name="verify" value="Submit" />
    </form>
    
    
    <?php
    }
    ?>
    
    PHP:
     
    nico_swd, Nov 26, 2006 IP
  3. Alvin

    Alvin Notable Member

    Messages:
    2,076
    Likes Received:
    164
    Best Answers:
    0
    Trophy Points:
    210
    #3
    Alvin, Nov 26, 2006 IP