2017 © Pedro Peláez
 

library laravel-agegate

A Laravel 4 package for adding an agegate to a site

image

fbf/laravel-agegate

A Laravel 4 package for adding an agegate to a site

  • Tuesday, May 6, 2014
  • by neilcrookes
  • Repository
  • 5 Watchers
  • 5 Stars
  • 618 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

Laravel-Agegate

A Laravel 4 package for adding an age gate to a site, (*1)

Features

  • Redirects requests for guarded routes to agegate URL
  • Agegate form with input type=date or select tags for year, month and day
  • Configurable url for agegate, minimum age, cookie name, cookie value
  • Sets 'forever', or 'session' or X minute (configurable) cookie if user is old enough
  • Redirects user back to the URL they were trying to access
  • Optionally allows bots/crawlers/spiders through age gate using one of 3 approaches

Installation

Add the following to you composer.json file, (*2)

"fbf/laravel-agegate": "dev-master"

Run, (*3)

composer update

Add the following to app/config/app.php, (*4)

'Fbf\LaravelAgegate\LaravelAgegateServiceProvider'

Publish the config, (*5)

php artisan config:publish fbf/laravel-agegate

Configuration

URI of the agegate page, (*6)

'agegate_uri' => 'agegate',

The minimum age to access the site, (*7)

'minimum_age' => 18,

The input type to use. Choices are: "date" for html5 input type="date" "select" for 3 select tags for day, month and year, (*8)

'input_type' => 'select',

The name of the cookie to set. Change this to whatever you want, (*9)

'cookie_name' => 'age_ok',

The value of the cookie to set. Change this to something unique, (*10)

'cookie_val' => 'hell yeah!',

The age of the cookie to set. Options are 'forever', an integer (minutes) or the default is for the session, (*11)

'cookie_age' => 'forever',

Determines whether the user can try again, if they entered a dob that makes them too young, or not. This lasts the session, (*12)

'can_try_again' => false,

The view that should be rendered for the agegate. You can use the bundled view, or specify your own and use @include('laravel-agegate::agegate') to get the agegate form and validation errors, (*13)

'view' => 'laravel-agegate::agegate',

The mode for allowed user agents (see section on Allowing bots etc below), (*14)

'allowed_user_agents.mode' => 'phpbrowscap_crawler'

The strings for allowed user agents, for the mode = exact or mode = contains setting (see section on Allowing bots etc below), (*15)

'allowed_user_agents.strings' => array(...)

Usage

Register the filter by adding the following to app/filters.php, (*16)

Route::filter('agegate', 'Fbf\LaravelAgegate\LaravelAgegateFilter');

and apply it to the routes you want to protect by adding the following to app/routes.php, (*17)

Route::when('my/routes/*', 'agegate');

or, (*18)

Route::group(array('before' => 'agegate'), function()
{
    // My routes
});

You also need to add the agegate routes to your app/routes.php, for example:, (*19)

Route::get(
    Config::get('laravel-agegate::agegate_uri'),
    'Fbf\LaravelAgegate\AgegateController@agegate'
);

Route::post(
    Config::get('laravel-agegate::agegate_uri'),
    array(
        'before' => 'csrf',
        'uses' => 'Fbf\LaravelAgegate\AgegateController@doAgegate'
    )
);

If you are using route prefixes in combination with the agegate filter, you can do the following:, (*20)

Route::get(
    Request::segment(1).'/'.Config::get('laravel-agegate::agegate_uri'),
    'Fbf\LaravelAgegate\AgegateController@agegate'
);

Route::post(
    Request::segment(1).'/'.Config::get('laravel-agegate::agegate_uri'),
    array(
        'before' => 'csrf',
        'uses' => 'Fbf\LaravelAgegate\AgegateController@doAgegate'
    )
);

Allowing bots/crawlers/spiders through

You can prevent them by setting the config setting allowed_user_agents.mode to none, (*21)

If you do want to allow certain user agents through the package provides 3 approaches:, (*22)

  • Using phpbrowscap_crawler, (*23)

    This is a composer package that is installed as a dependency of the agegate package., (*24)

    Simply it is a version of the browscap project that doesn't require you to have specified the path to the browscap.ini file in your php.ini., (*25)

    The project maintains an up-to-date list of platforms, browsers, versions and capabilities and also details of crawlers. It's the crawlers data that this package uses., (*26)

    The way it works is to fetch and cache a copy of the latest browscap.ini file and create a php array cache version too, then it looks us the user agent string in this file to determine if it's a crawler., (*27)

    As you may guess, this takes a while the first time it fetches and caches the file, but subsequent checks, once it has the cached copy, are really fast., (*28)

    phpbrowscap also self-updates the cache too, so it will always be up-to-date., (*29)

    The disadvantage of the overhead on a very occasional request (which may be a bot you don't care about anyway) is outweighed by the advantage of having a more robust test to ensure the filter is not applied to any bots, since the alternative methods (see below) have room for error in that you may not come up with a list of strings to correctly match all the user agents you intended to target., (*30)

  • Using contains, (*31)

    Add a list of strings to the allowed_user_agents.strings config setting and if the user agent contains one of these strings, the age gate will not be applied., (*32)

  • Using exact, (*33)

    Add a list of strings to the allowed_user_agents.strings config setting and if the user agent exactly matches one of these strings, the age gate will not be applied., (*34)

The Versions

06/05 2014

dev-master

9999999-dev

A Laravel 4 package for adding an agegate to a site

  Sources   Download

MIT

The Requires

 

24/04 2014

v0.4.0

0.4.0.0

A Laravel 4 package for adding an agegate to a site

  Sources   Download

MIT

The Requires

 

14/03 2014

v0.3.0

0.3.0.0

A Laravel 4 package for adding an agegate to a site

  Sources   Download

MIT

The Requires

 

12/03 2014

v0.2.0

0.2.0.0

A Laravel 4 package for adding an agegate to a site

  Sources   Download

MIT

The Requires

 

25/10 2013

v0.1.0

0.1.0.0

A Laravel 4 package for adding an agegate to a site

  Sources   Download

MIT

The Requires