Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12
Like Tree1Likes

Thread: does anyone have an age verification script?

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Member #
    25310
    hi guys,

    i am making a website that sells wine and i am trying to get a script for age verification...

    i have searched for hours but haven't found anything that works properly!

    i just need it to be something like "are you of legal drinking age?"

    they click yes and go through to the site...

    or they click no and the go to google or whatever.


    i need it for a joomla website. i have looked in to extensions but they were expensive. i need it to save the cookie for a while as well.

    if someone could save my life i would be soooo grateful. my brain hurts from the over complication, i just need something simple and easy to use!

    thanks x x x

  2.  

  3. #2
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    137 times
    Using the search function of the forum does indeed find what you're looking for
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  4. #3
    Junior Member
    Join Date
    Nov 2010
    Posts
    6
    Member #
    25310
    yeah i already looked but the script that mosely posted doesn't work. it almost does... but it throws up errors on the page. saying something about over18 isn't assigned.

    anyone else?

  5. #4
    Member DerrickE's Avatar
    Join Date
    Jul 2007
    Location
    Houston, TX
    Posts
    58
    Member #
    15580
    Liked
    10 times
    Made just for you

    Can see a demo here: Age Verification <-- This is the exact script as below

    This comes in 2 sections, keep my credit intact if you use it. If you need help installing it, let me know.
    This is very simple to implement:

    Add this code to the top of your index.php page before anything else:
    Modify:
    $redirect_url to be the page to redirect to. The redirect page is a brand new page you create; not associated with joomla. The code for it is further down.
    $expires to be the length of time before the session time out. By default it is -1 which is once per browser opening. They open the browser, go to your site, it only requests it once unless they close their browser.

    PHP Code:
    <?php
    /*
    gatekeeper by: TDXP.net
    */
    function gatekeeper(){
        
    $redirect_url='http://tdxp.net/wdftest/gatekeeper/gatekeeper.php';
        
    $expires=-1;
        
    session_start();
        
    $validated=false
        if(!empty(
    $_COOKIE["gatekeeper"])) { $validated=true; }
        if(!
    $validated && isset($_SESSION['gatekeeper'])) { $validated=true; }
        if(
    is_numeric($expires) && $expires==-&& !isset($_SESSION['gatekeeper'])) { $validated=false; }
        if(
    $validated) { return; }
        else {
        
    $redirect_url=$redirect_url."?return=".$_SERVER['REQUEST_URI']."&x=".$expires;
        
    Header('Location: '.$redirect_url);
        exit(
    0);
        }
    }
    gatekeeper();
    ?>
    The gatekeeper.php page
    Leave everything intact, can change the html code at the bottom to style as you wish. This is the php method which works even if they have javascript disabled.

    PHP Code:
    <?php
    /*
    gatekeeper by: TDXP.net
    */
    session_start();
    if(
    $_SERVER['REQUEST_METHOD']=='POST')
    {
    if(isset(
    $_POST['YES']))
    {
    $redirect=isset($_GET['return'])?urldecode($_GET['return']):'./';
    $expire=isset($_GET['x']) && is_numeric($_GET['x'])?intval($_GET['x']):-1;
    if(
    $expire==-1)
    {
    $_SESSION['gatekeeper']="yes";
    header("location: ".$redirect);
    exit(
    0);
    }
    if(
    $expire==0)
    {
    setcookie("gatekeeper""yes",mktime(0,0,0,01,01,date("Y")+30));
    $_SESSION['gatekeeper']="yes";
    header("location: ".$redirect);
    exit(
    0);
    }
    setcookie("gatekeeper""yes",(time()+$expire));
    $_SESSION['gatekeeper']="yes";
    header("location: ".$redirect);
    exit(
    0);
    }else{
    header("location: http://www.google.com");
    exit(
    0);
    }
    }

    ?>
    <html>
    <head>
    <title>Age Verification</title>
    </head>
    <body>
    <form action="" method="POST">
    <p>Are you of drinking age?</p>
    <input name="NO" type="Submit" value="NO - Leave" />
    <input name="YES" type="Submit" value="Yes - Enter" />
    </form>
    </body>
    </html>

  6. #5
    Junior Member
    Join Date
    Jul 2011
    Posts
    1
    Member #
    28381
    Hi,

    i found this solution trough google and it would be great for my joomla website. In the example page of DerrickE is everything working fine, but on my site the function will not do it. A click on "Yes - Enter" and it show me the same page again. So, i cant get on my site, as long as the code stays in the index.php of my template. I put the gatekeeper.php in the root and adjust the redirect_url in the index.php code.
    I think, i have everything bring in correctly - but it will not work. Is there may a server-restriction to consider, like mod_rewrite or something like that?

    Thanks!

  7. #6
    Member DerrickE's Avatar
    Join Date
    Jul 2007
    Location
    Houston, TX
    Posts
    58
    Member #
    15580
    Liked
    10 times
    This uses no mod_rewrite or anything. It should work out of the box. Message me your site url and I'll take a look and see what's going on. It's probably the cookie not being set or something simple.

  8. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Member #
    34962
    Hi, I know this thread is very old but I have the same issue as Gerri. I tested the script in a separate directory on my host and it works great; but once I embed the function code on my joomla template index file it shows the same page again.

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    Have you tried to search for a real Joomla plugin?
    https://www.google.com/search?q=joom...in&btnG=Search


  10. #9
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Member #
    34962
    Have you tried to search for a real Joomla plugin?
    https://www.google.com/search?q=joomla age verification plugin&btnG=Search
    Yes I've done it but I would like to have just a php code since I had age check pro for joomla 1.5 and now it doesn't work in 2.5. I'm trying to keep away from plugins that work for specific versions of joomla as much as I can.

  11. #10
    Junior Member
    Join Date
    Jan 2013
    Posts
    3
    Member #
    34962
    I found a code which helped me. I modified it a little bit to meet my expectations.It has javascript on it; but it does NOT need it in order to work. The javascript code only adds some cosmetic functions.So it WORKS WITH JAVASCRIPT DISABLED.I added some helpful comments to the code to explain how it works, and left all the html and css code; just replaced the content related to my website by "change it to whatever".I also created a php code to go back to visited url. Let's say someone visit a link in your website (site.com/categories/category2.html), and gets redirected to the verify page. When the age is verified it redirects to site.com/categories/category2.html, not to site.com. I left a comment to change it to the main page if you want.
    First:verify.php file

    Code:
    <?php
        /*if the cookie already exists from a previous remember me button click then skip this page*/
        error_reporting(E_ALL ^ E_NOTICE); //I don't know if that's right, but it works to keep the 1 error off the page - not by fixing, but hiding the error of legal not defined
        if($_COOKIE['legal'] == "yes")
                        {
                        header("Location: index.php");
                        }
    
        if (isset($_POST['checkage']))
        {
        $day = '';
        $month = '';
        $year = '';
        $minage = '18';
    
        if(isset($_POST['day']))
                {
                $day = $_POST['day'];
                }
    
        if(isset($_POST['month']))
                {
                $month = $_POST['month'];
                }
    
        if(isset($_POST['year']))
                {
                $year = $_POST['year'];
                }
    
        $birthstamp = mktime(0, 0, 0, $month, $day, $year);
        $diff = time() - $birthstamp;
        $age_years = floor($diff / 31556926);
    
        if($age_years >= $minage)
                {
                if($rembox=="yes")
                        {
                        setcookie('legal', 'yes', time() + 31556926);
                        }
                        else{
                        setcookie('legal', 'yes', 0);
    
                        }
                        $url = $_COOKIE['agecheckgoback'];/*redirects to the url visited before. if you want to redirect to the main site, replace $_COOKIE['agecheckgoback'] by "index.php" or "/"(both with quotes)*/
                }
        else
                {
                setcookie('legal', 'no', 0);
                $url = 'http://www.disney.com/';
                }
    
        header('Location: '.$url.'');
        }
    ?>
    
        <html>
        <head>
        <meta name="keywords" content="change to keywords of your website" />
      <meta name="title" content="change to your website name" />
      <meta name="description" content="change to your website description" />
      <title>change to your website name</title>
        <style type="text/css">
            /*change only colors if you don't know what you are doing*/
        body{color:#000; background-color:#900000;}
        a{ color:#F9F9D1; text-decoration: none;}
        a:hover{ color:#000000;}
        .wrap {
        margin-top:20%;
        width: 100%;
        text-align: center;
        }
        .ageimg{
        width: 600px;
        margin-bottom: 10px;
        }
        .terms{
          width: 50%;
          color: #F9F9D1;
          margin-left: 25%;
          margin-right:25%;
          margin-top: 10px;
          margin-bottom: 10px;
          padding: 10px;
          text-align: left;
          border: solid 1px #fff;
        }
        </style>
      <script src="jquery.js"></script>
    <script src="fade.js" type="text/javascript"></script>
    </head>
    
    <script language=Javascript>
      <!--
      function isNumberKey(evt)
      {
        var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
            return false;
    
        return true;
      }
      //-->
    </script>
    <script type="text/javascript">
    function jumpField(elmnt,content)
    {
    if (content.length==elmnt.maxLength)
    {
    next=elmnt.tabIndex
    if (next<document.forms[0].elements.length)
        {
        document.forms[0].elements[next].focus()
        }
        }
    }
    </script>
    
    <body id="body" OnLoad="document.ageVerifyForm.month.focus();">
            <div class="wrap">
            <div class="logo"><img alt="change to Website Name" src="./images/logo.png"></div>
            <div class="ageterms"><img class="ageimg" alt="18+ Age Warning!" src="./images/18.png"></div>
            <div class="terms">By entering this Site, you agree to the following terms and conditions: You certify that you are 18 years of age or older, and are not offended by sexually explicit content. You agree that you will not permit any person(s) under 18 years of age to have access to any of the materials contained with this Site.This website uses cookies to manage authentication, navigation, and other functions. By using our website, you agree that we can place these types of cookies on your device.</div>
    <p style="color:#fff;">Please verify your date of birth to enter the site.</p>
    <form id="ageVerifyForm" name="ageVerifyForm" action="" method="POST" onsubmit="return formCheck(this);">
    <input type="text" tabindex="1" onkeypress="return isNumberKey(event)" onkeyup="jumpField(this,this.value)" id="month" name="month" maxlength="2" size="2" required="required" value="MM" onfocus="value=''" />
    <input type="text" tabindex="2" onkeypress="return isNumberKey(event)" onkeyup="jumpField(this,this.value)" id="day" name="day" maxlength="2" size="2" required="required" value="DD" onfocus="value=''"  />
    <input type="text" tabindex="3" onkeypress="return isNumberKey(event)" onkeyup="jumpField(this,this.value)" id="year" name="year" maxlength="4" size="4" required="required" value="YYYY" onfocus="value=''" />
    <br />
    <br>
    <input type="submit" value="Verify To Enter Site" id="submit" name="checkage" />
    </form>
    <script language="JavaScript">
    <!--
    function formCheck(formobj){
    // Enter name of mandatory fields
    var fieldRequired = Array("month", "day", "year");
    // Enter field description to appear in the dialog box
    var fieldDescription = Array("month", "day", "year");
    // dialog message
    var alertMsg = "Please complete the following fields:\n";
    
    var l_Msg = alertMsg.length;
    
    for (var i = 0; i < fieldRequired.length; i++){
        var obj = formobj.elements[fieldRequired[i]];
        if (obj){
            switch(obj.type){
            case "select-one":
                if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            case "select-multiple":
                if (obj.selectedIndex == -1){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            case "text":
            case "textarea":
                if (obj.value == "" || obj.value == null){
                    alertMsg += " - " + fieldDescription[i] + "\n";
                }
                break;
            default:
            }
            if (obj.type == undefined){
                var blnchecked = false;
                for (var j = 0; j < obj.length; j++){
                    if (obj[j].checked){
                        blnchecked = true;
                    }
                }
    
            }
          }
        }
    
    if (alertMsg.length == l_Msg){
        return true;
        }else{
        document.getElementById("error").innerHTML="All Fields Must be Filled out";
        return false;
        }
    }
    // -->
    </script>
    <p id="error"></p><br />
            </div>
        </body>
        </html>
    Second:Place this code in every page on your website ON THE FIRST LINE. If the website use templates, place it in the index.php or index.tpl of the template directory and other files needed.I used it in a joomla site.
    Code:
    <?php
    /*Set Cookie to go back to the url before the age check form*/
    $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    setcookie('agecheckgoback',$url,0,'/');
    
    ?><?
    /*Set cookie for age check*/
        if(!isset($_COOKIE['legal'])) {
        header("Location: /verify.php");
        }
    
        if($_COOKIE['legal'] == "no")
                        {
                        header("Location: http://www.disney.com/");
                        }
    
    ?>
    Here ends the function part. The next part is the cosmetic or appearance part:

    Third:The image I used on my website:

    Fourth:The fade.js file:
    Code:
    $(document).ready(function () {
            $('#body').hide().fadeIn(3000);/*Set to 3 seconds.Change it to the time you want.*/
            });
    Fifth:jquery.js file. You can download the last jquery at jquery.com/download/ or just point to the file with:
    Code:
    <script src="http://code.jquery.com/jquery-VERSION.min.js"></script>
    Visit their page for more info.
    and, That's all!
    Happy age restriction page


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Search tags for this page

age verification code

,

age verification code for website

,
age verification for my website
,
age verification html
,
age verification html code for website
,
age verification javascript code
,

age verification script

,

free age verification html code

,

free age verification script

,

html age verification script

Click on a term to search for related topics.
All times are GMT -6. The time now is 05:21 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com