Download the PHP package reflar/cookie-consent without Composer

On this page you can find all versions of the php package reflar/cookie-consent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package cookie-consent

Cookie Consent by FriendsOfFlarum

MIT license Latest Stable Version Total Downloads OpenCollective

A Flarum extension. Adds a cookie consent banner, with accept, decline and configure options for your users.

Features

Installation

Updating

Configuration

Enable the extension and the banner appears. Everything else is optional.

To test, clear the cc_cookie cookie for your site, or use a private window.

Cookie categories

Three categories are built in — necessary, analytics and marketing. Only necessary is used until an extension declares cookies for the others, so a forum running nothing that tracks shows a single section.

necessary covers Flarum's own cookies:

Cookie Purpose
flarum_session Keeps you signed in
flarum_remember Signs you back in on your next visit
locale Your chosen display language
cc_cookie Your cookie choice, so you aren't asked again

These can't be declined and are never erased. Other categories appear when an installed extension declares them.

Wording

Banner text isn't an admin setting — it lives in the language files so it can be translated. Override the keys with FoF Linguist or a language pack:

Undeclared cookies

Extensions that haven't adopted the extender are invisible to the category system. The Erase cookies no extension has declared setting handles those: on decline, any cookie nothing declared is erased.

It's blunt. An extension that hasn't adopted the extender will lose its cookies, which may break it. Use the allow list to spare anything it needs.

Limitations

The extender covers third party <script> tags, which is what most trackers use. It won't help with:

Anything in that list needs a server-side consent check.

Extending

If your extension sets cookies, or loads a script that does, declare it. Add this to your extend.php:

Extend\Conditional keeps it a soft dependency — without fof/cookie-consent installed, your extension behaves as before.

Add it to your composer.json so it boots first:

Declaring cookies

category() creates a category, or adds to one another extension already declared, so several extensions can share analytics.

Method Does
cookie('_gid', $key) Declares one cookie, with a translation key describing it
cookiePattern('^_pk_', $key) Same, for a family of cookies
essential() Always on, can't be declined, never erased
reloadOnReject() Reloads the page after rejection
translations($title, $description) Names the category's own strings — third-party categories only

Declared cookies are erased when the category is declined, and listed in the preferences dialog either way.

The description key is optional but worth supplying: without one the dialog shows the cookie name and an empty purpose.

reloadOnReject() is for scripts that can't cleanly undo themselves once loaded — most analytics libraries.

Gating scripts

gate() holds your <script> tags until the category is accepted.

Tags you add to the document head are rewritten to type="text/plain" with a data-category. The browser treats them as data, so it never fetches the src and never runs them — no request, no cookie. On acceptance the consent library swaps the type back and the script runs.

Tags you've already marked type="text/plain" are left alone, so you can gate them yourself. JSON-LD, import maps and speculation rules are never gated.

Categories and translations

necessary, analytics and marketing are defined here, translations included. Use those keys where they fit — several extensions contributing to analytics then share one section, rather than each shipping its own wording for it. Passing translations() on one of these does nothing; ours win.

Any other key is yours, and needs its own strings:

Cookie descriptions are always yours, whichever category they sit in — only you know what _lc does. Ship the strings with your extension:

Reacting to consent

If your JavaScript needs to run after a gated script loads, listen for the consent events:

FoF Analytics uses all of the above if you want a working example.

Links


All versions of cookie-consent with dependencies

PHP Build Version
Package Version
Requires flarum/core Version ^2.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package reflar/cookie-consent contains the following files

Loading the files please wait ...