简体   繁体   中英

Code to block cookies in EU e-Privacy Directive

I am using Joomla 2.5.4 extension EU e-Privacy Directive to block cookies and display message about Cookies. I need to know about the code/function which used to block the cookies

Please help me

Looking at the code for that plugin, there are three main things that happen:

  1. Use GeoIP to detect the user's country
  2. Remove all Set-Cookie headers if the detected country is a member of the EU.
  3. Prompt the user if they want to allow cookies, and bypass the Set-Cookie removal on further requests if the user allows non-essential cookies.

The second step can be achieved with the following, though note that this removes all cookie headers:

header_remove('Set-Cookie');

If you're looking for an existing implementation, GitHub has plenty of results for cookie law and cookie consent . Cookie-consent-handler is the most generic PHP implementation I found.

See also:

Update:

Regarding your comment about how to remove all cookies except the session cookie, you could replace the _cleanHeaders method in that plugin with the following (assumes PHP>=5.3):

function _cleanHeaders() {
    $retain = array_filter(headers_list(), function($header) {
        return strpos($header, session_id()) !== false;
    });

    header_remove('Set-Cookie');

    array_walk($retain, function($header){
        header($header);
    });
}

Why is there always such an aversion to asking the developer? (it's me, by the way)

Sino Thomas - you flood stackoverflow with questions about my extension - yet never ask me. Planning a fork?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM