如何在 Joomla 3.x 中禁用所有访客 cookie

How to disable all visitors cookies in Joomla 3.x

我正在尝试为我的 Joomla 网站禁用所有访问者 cookie。

我找到了一些教程,但它们是针对 Joomla version:1.x

有什么建议吗?

要避免普通访问者的所有 cookie,您需要按照以下步骤操作。

First of all: Deactivate site statistics! Global configuration -> Statistics -> Statistics: No. This will stop the "mosvisitor" cookie.

Don't use the Template Chooser module, because it uses a cookie named "jos_user_template".

Be careful with components: Some might start their own PHP session. 

Now to the main point: comment out line 697 of /includes/joomla.php like this:



// setcookie( $sessionCookieName, '-', false, '/' );

附加:注释掉 /offline.php 中的第 25 行:

// session_start(); 

这似乎是旧版本的产物。

该解决方案与 Joomla 版本 1.x 和 2.x 中删除 cookie 的解决方案非常相似。所以我们将使用相同的条件和原则。

如果您更改这两个文件,那么其他文件可能不起作用。仅当您知道自己在做什么并且知道其他一切都会起作用时才更改此设置。因为你可以破坏整个网站!

您必须编辑两个文件 /libraries/src/Application/CMSApplication.php 和 libraries/joomla/session/handler/native.php

libraries/src/Application/CMSApplication.php 中更改第 166 行附近的代码,并在方法 if (substr($_SERVER['SCRIPT_NAME'] , 0 , 14) == "/管理员"){

public function checkSession()
    {
      if (substr($_SERVER['SCRIPT_NAME'] , 0 , 14) == "/administrator"){ // added condition
        $db = \JFactory::getDbo();
        $session = \JFactory::getSession();
        $user = \JFactory::getUser();

            // ... rest of code
      }
}

libraries/joomla/session/handler/native.php 中,更改第 229 行周围的代码,在方法中为整个代码添加 if 条件,就像在上一个文件中一样

private function doSessionStart()
    {
      if (substr($_SERVER['SCRIPT_NAME'] , 0 , 14) == "/administrator"){ // added condition
        // Register our function as shutdown method, so we can manipulate it
        register_shutdown_function(array($this, 'save'));

        // ... rest of code
      }
 }

这适用于 Joomla 3.8.2

注意:每次 Joomla 更新后,您必须再次编辑这两个文件并测试此解决方案是否仍然有效。

在管理 Joomla 设置(系统 => 配置)中设置 cookie 路径“/administrator”。 然后仅为管理区域创建会话 cookie。