ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Age Verification Page

January 10, 2011 9:54am

Subscribe [1]
  • #1 / Jan 10, 2011 9:54am

    HelloComputer

    2 posts

    Hi,

    I am trying to create an age verification page for an alcohol site.
    When the user hits ANY page on the site it must redirect to the age verification page. Once they have verified that they are over 18 they can then continue using the site.
    They can browse the site while the session is still active.

    I have tried a cookie plugin but the problem with this is that it goes to the specific page (EG - Home, about, products etc) first and only then redirects to the gateway(verification) page. So it shows the page for a brief moment and then redirects. I dont want this.
    I want it to stay on the verification page until the user has entered their age.

    Any suggestions are welcome.

    Thanks.

  • #2 / Jan 19, 2011 5:29pm

    Adam Dorsey

    1439 posts

    A little PHP will do the trick. Add the following code to the top (after <?php) of the index.php page in the root.

    if ($_COOKIE['of_age'] == "")
    {
        header("Location: <a href="http://your-site.com/verification.php">http://your-site.com/verification.php"</a>);
        exit;
    }
    elseif ($_COOKIE['of_age'] == "no")
    {
        header("Location: <a href="http://your-site.com/verification-failed.php">http://your-site.com/verification-failed.php"</a>);
        exit;
    }

    This will check for a cookie called “of_age” and see if it doesn’t exist or if it is set to no.

    Then add a verification.php file in the root, with your form and this bit of php code at the top:

    <?php
    
    if (isset($_COOKIE['of_age']) == "")
    {
    
        if (isset($_POST['of_age']))
        {
            
            $v = $_POST['of_age'];
            
            setcookie('of_age', $v, time() + (86400 * 7), '', '.your-site.com'); // 86400 = 1 day
            
            if ($v == "yes")
            {
                header("Location: <a href="http://your-site.com">http://your-site.com"</a>);
                exit;
            }
            if ($v == "no")
            {
                header("Location: <a href="http://your-site.com/verification-failed.php">http://your-site.com/verification-failed.php"</a>);
                exit;
            }
    
        }
    
    }
    elseif (isset($_COOKIE['of_age']) == "yes")
    {
        header("Location: <a href="http://your-site.com">http://your-site.com"</a>);
        exit;
    }
    elseif (isset($_COOKIE['of_age']) == "no")
    {
        header("Location: <a href="http://your-site.com/verification-failed.php">http://your-site.com/verification-failed.php"</a>);
        exit;
    }
    
    ?>

    Form:

    <form action="verification.php" method="post">
        
        <h1>Are you over 21 years of age?</h1>
        
        Yes <input type="radio" name="of_age" value="yes"/>    No <input type="radio" name="of_age" value="no"/> 
            
        <input type="submit" value="Submit" /></p>
    
    </form>

    Then add verification-failed.php in the root. This can really be a plain html file. Just some kind of error message.

    Anyway. That’s it. Good luck!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases