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

4

我想禁用我 Joomla 网站的所有访客 Cookie。

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

有什么建议吗?


我遇到了同样的问题。我的当前解决方法是使用Apache mod_headers删除Set-Cookie HTTP头。此外,我还遵循了这个 ,虽然它本身并不能解决问题,但可以在一定程度上减少数据库负载。虽然我对此不太满意,但总比没有好。 - balping
主要问题在于 Joomla 开发人员认为实现这样的功能会过于复杂,因此很快就不会有一个清晰的解决方案,恐怕。 - balping
3个回答

5
该解决方案与删除Joomla 1.x和2.x版本中的cookies的解决方案非常相似。因此,我们将使用相同的条件和原则。
如果您更改这两个文件,则可能会使其他某些功能无法正常工作。只有在您知道自己在做什么,并且知道其他所有功能都能正常工作时,才应进行更改。因为您可能会破坏整个网站!
您必须编辑两个文件/libraries/src/Application/CMSApplication.php和libraries/joomla/session/handler/native.php 在libraries/src/Application/CMSApplication.php中,更改大约166行左右的代码,并添加if条件以控制整个方法中的代码if (substr($_SERVER['SCRIPT_NAME'] , 0 , 14) == "/administrator"){
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更新后,您必须再次编辑这两个文件,并测试此解决方案是否仍然有效。


checkSession() 在3.8.8中有所不同。 - balping
也适用于3.9.20版本 - perLHawk

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

1
如果您是Joomla用户,请加入[joomla.se] Stack Exchange并看看是否可以帮助我们解决一些问题。 - mickmackusa

-1
为了避免普通访问者的所有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(); 

这似乎是旧版本的一个遗留问题。


谢谢你的回答,Kaif。但是这个教程是针对 Joomla 1.x 的。在 Joomla 3.x 版本中,全局配置 > 静态选项不存在。 此外,在 /includes/ 文件夹中没有名为 joomla.php 的文件。 - Stanislav Balev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接