0

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

Sino Thomas
  • 141
  • 1
  • 7
  • 22

2 Answers2

1

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);
    });
}
Community
  • 1
  • 1
Stecman
  • 2,890
  • 20
  • 18
  • I am using this plugin in Multi-Langauge website and i added new session variable in the language module, When i activated this plugin it block the session variable in the language module. How it possible to prevent blocking of session variable ? – Sino Thomas Sep 20 '13 at 11:17
  • You'd need to edit the `_cleanHeaders` function in the plugin to achieve that, since it wipes out all Set-Cookie headers as it is currently. You'd need to retain the header that sets the session cookie from `headers_list()`, and set it again after the `header_remove()` call using `header()`. – Stecman Sep 20 '13 at 11:29
  • ok, is it possible to restore the cookie of corresponding session variable. Please help me – Sino Thomas Sep 20 '13 at 12:32
  • Variables in the $_SESSION super-global are stored on the server, not sent in cookies (see [Intro to session](http://php.net/manual/en/intro.session.php)). A single cookie containing a session ID is used to relate any one client to a session on the server. I've updated my answer to show how to have the plugin you're using leave the session cookie untouched. – Stecman Sep 20 '13 at 13:39
  • Thanks..i need to know. How the plugin store value to know, the user is accept or decline. Which function keep track accept/decline the cookies and display the module action to restore cookies and remove cookies. Please give the details about functionality. – Sino Thomas Sep 25 '13 at 11:17
  • I suggest you have a look at the code for the plugin - it's very readable: http://pastebin.com/FCnpSQ7L – Stecman Sep 26 '13 at 00:11
-1

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?

Michael
  • 9,223
  • 3
  • 25
  • 23