当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

laravel-cookie-consent

授权协议 MIT License
开发语言 PHP
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 汪才英
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

Make your Laravel app comply with the crazy EU cookie law

All sites owned by EU citizens or targeted towards EU citizens must comply with a crazy EU law. This law requires a dialog to be displayed to inform the users of your websites how cookies are being used. You can read more info on the legislation on the site of the European Commission.

This package provides an easily configurable view to display the message. Also included is JavaScript code to set a cookie when a user agrees with the cookie policy. The package will not display the dialog when that cookie has been set.

Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/laravel-cookie-consent

The package will automatically register itself.

Optionally you can publish the config-file:

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-config"

This is the contents of the published config-file:

return [

    /*
     * Use this setting to enable the cookie consent dialog.
     */
    'enabled' => env('COOKIE_CONSENT_ENABLED', true),

    /*
     * The name of the cookie in which we store if the user
     * has agreed to accept the conditions.
     */
    'cookie_name' => 'laravel_cookie_consent',

    /*
     * Set the cookie duration in days.  Default is 365 * 20.
     */
    'cookie_lifetime' => 365 * 20,
];

Usage

To display the dialog all you have to do is include this view in your template:

//in your blade template
@include('cookie-consent::index')

This will render the following dialog that, when styled, will look very much like this one.

dialog

The default styling provided by this package uses TailwindCSS v2 to provide a floating banner at the bottom of the page.

When the user clicks "Allow cookies" a laravel_cookie_consent cookie will be set and the dialog will be removed from the DOM. On the next request, Laravel will notice that the laravel_cookie_consent has been set and will not display the dialog again

Customising the dialog texts

If you want to modify the text shown in the dialog you can publish the lang-files with this command:

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-translations"

This will publish this file to resources/lang/vendor/cookie-consent/en/texts.php.

return [
    'message' => 'Please be informed that this site uses cookies.',
    'agree' => 'Allow cookies',
];

If you want to translate the values to, for example, French, just copy that file over to resources/lang/vendor/cookie-consent/fr/texts.php and fill in the French translations.

Customising the dialog contents

If you need full control over the contents of the dialog. You can publish the views of the package:

php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-views"

This will copy the index and dialogContents view files over to resources/views/vendor/cookie-consent. You probably only want to modify the dialogContents view. If you need to modify the JavaScript code of this package you can do so in the index view file.

Using the middleware

Instead of including cookie-consent::index in your view you could opt to add the Spatie\CookieConsent\CookieConsentMiddleware to your kernel:

// app/Http/Kernel.php

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        \Spatie\CookieConsent\CookieConsentMiddleware::class,
    ];

    // ...
}

This will automatically add cookie-consent::index to the content of your response right before the closing body tag.

Notice

The legislation is pretty very vague on how to display the warning, which texts are necessary, and what options you need to provide. This package will go a long way towards compliance, but if you want to be 100% sure that your website is ok, you should consult a legal expert.

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email freek@spatie.be instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

 相关资料
  • Laravel sanctum让我有点头疼,因为我花了几个小时试图弄清楚为什么route不返回任何内容。最初未找到相同的路由返回404,但在添加 。我也运行了laravel的新安装,PHP工匠优化,清除了我的浏览器历史,检查了邮递员中的endpoint,但仍然相同的异常

  • Cookie在Web应用程序上处理用户会话时发挥着重要作用。 在本章中,您将学习如何在基于Laravel的Web应用程序中使用cookie。 创建Cookie Cookie可以由Laravel的全局cookie帮助程序创建。 它是Symfony\Component\HttpFoundation\Cookie一个实例。 可以使用withCookie()方法将cookie附加到响应中。 创建Illum

  • 我正在Laravel应用程序中为Cors使用中间件。 我的文件如下所示: 我设置cookie作为回应,如下所示: 最后,我从运行在 它给我一个错误,说不允许CORS(经典CORS错误)。 但是当我从响应中删除cookie时,它就可以正常工作了。 我还需要什么设置才能让它工作?

  • 本文向大家介绍Laravel 登录后清空COOKIE的操作方法,包括了Laravel 登录后清空COOKIE的操作方法的使用技巧和注意事项,需要的朋友参考一下 需求 在Laravel 登陆立即清空保存的COOKIE数组 实现 关键代码 Cookie::queue(Cookie::forget('subscribe')); 但是Cookie::make($name,'hit.article',$va

  • 我将为我的应用程序创建一个单一登录界面。另一个应用程序发送一个AJAX POST请求,我对用户进行身份验证并返回响应。会话cookie已设置,但未加密。 相关守则 Kernel.php中我的“api”部分 我的路线(无其他中间件) Kernel.php中的EncryptCookies类似乎对AJAX post请求没有任何影响,但仅对会话部分有效。当我手动添加cookie时,如 它被加密了! 当我在

  • 本文向大家介绍解决Laravel无法使用COOKIE和SESSION的问题,包括了解决Laravel无法使用COOKIE和SESSION的问题的使用技巧和注意事项,需要的朋友参考一下 COOKIE和SESSION的具体使用百度和官方文档上都有。 但是,文档里没有说明必须经过相应的中间件才能使用,百度搜索结果都是彼此copy的bullshit!!! 方法如图所示,对应的路由必须使用下列中间件,COO