Simple code to end a Drupal cookie?

With one click, this simple script will execute multiple terminations:

Moodle

Elgg

2 MyBB and

(not) Drupal.

<?php setcookie( 'Elgg', '', -3600, '/', '.domain.com', false, false); setcookie( 'http_auth_ext_complete', '1', -3600, '/d/', '.domain.com', false, false); // setcookie( 'http_auth_ext_complete', '1', -3600, '/d/', 'domain.com', false, false); setcookie( 'mybbuser', '', -3600, '/', '.domain.com', false, false); setcookie( 'mybbuser', '', -3600, '/bb/', '.domain.com', false, false); // unset all 3 Moodle cookies, the lazy way if (isset($_SERVER['HTTP_COOKIE'])) { $cookies = explode(';', $_SERVER['HTTP_COOKIE']); foreach($cookies as $cookie) { $parts = explode('=', $cookie); $name = trim($parts[0]); setcookie($name, '', time()-1000); setcookie($name, '', time()-1000, '/'); } } ?> 

This works on four sites, but the Drupal cookie will not go away. How can I do the same with Drupal?

Note: Drupal uses a "host" instead of a "domain", neither with "or" nor with. still working.

Thanks.

EDIT: I'm sure the cookie had β€œHost domain.com” twice and the other standard format β€œDomain.domain.com” was used on the other input.

The cookie named "http_auth_ext_complete" expires and I am still logged in. Drupal uses a second cookie with a session identifier as the name of cookie +, there is a corresponding entry in the session database table, as well.

+4
source share
1 answer

The session cookie name used by Drupal is not constant, but is based on the MD5 hash of the cookie domain of a specific Drupal installation - see conf_init() in 'bootstrap.inc' for details (hashing occurs in the last line of the function).

This session cookie is one that you will need to eliminate in order to log out. If your script should only work for a specific Drupal instance, you can configure it to use a specific session cookie name (it will break if the cookie domain changes). If it is intended for more general use, you will need to create a dynamic version that mimics the way Drupal is created, that is, "SESS". md5 ([cookie_domain]), with some complications with SSL.

+4
source

Source: https://habr.com/ru/post/1311685/


All Articles