May 232011
 

After not being able to find a module that worked quite as we wanted, I created a simple Age Gate module for Drupal 7. This module very basic and has various hardcoded paths in it.

The module redirects all anonymous users to the agegate page and requires that they check the ‘Over 18’ checkbox before they can view content on the site. If they don’t check to box and press submit they get redirected to a page at the path ‘access-denied’ (this is the page we use on our site). The module is coded to allow non agegate access to logged in users, the ‘user/login’ page and the ‘access-denied’ page.

Download it here. Module is provided as is. Agegate Module for Drupal 7

  6 Responses to “Age gate for Drupal 7”

  1. right on girl! I was just looking for this EXACT mod for my new upcoming site!

  2. It is appropriate time to make some plans for the future and it’s time to be happy.
    I’ve read this publish and if I may just I want to recommend you some interesting issues or suggestions.
    Perhaps you could write subsequent articles referring to this article.
    I want to read more issues approximately it!

    Feel free to surf to my weblog :: lukebrayn

  3. This works nice. Is it hard to ade a .tpl to easily theme this page? I presume replacing the harcoded texts with some php? Could you help?
    Thank you.

  4. And can a cookie be set?

    e.g.

    /**
    * Function to set pass cookie.
    */
    function _age_verify_setcookie() {
    $expire_days = variable_get('age_verify_cookie', '');
    $expire = REQUEST_TIME + 60 * 60 * 24 * $expire_days;

    setcookie('age_verify', 'yes', $expire);
    }

    /**
    * Function to set the failure cookie.
    */
    function _age_verify_fail_setcookie() {
    $expire_days = variable_get('age_verify_cookie', '');
    $expire = REQUEST_TIME + 60 * 60 * 24 * $expire_days;

    setcookie('age_verify', 'no', $expire);
    }

    /**
    * Hook Init()
    * check for cookie and redirect to age_verify page or away from site
    */
    function age_verify_init() {
    $fail_redirect = variable_get('age_verify_failure_destination', '');

    if (!isset($_COOKIE['age_verify']) && arg(0, drupal_get_path_alias()) != 'age_verify') {
    drupal_goto('age_verify');
    }

    if (isset($_COOKIE['age_verify']) && $_COOKIE['age_verify'] == 'no' && arg(0, drupal_get_path_alias()) != 'age_verify') {
    header('Location: ' . $fail_redirect);
    }
    }

    Source.

  5. I can’t install the module, D7 says it contains no info file. It clearly does. But I get that error anyway.

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)