【问题标题】:OpenCart - "Invalid Token Session" error - how to fix now & prevent in the future?OpenCart - “无效的令牌会话”错误 - 如何现在修复并在未来预防?
【发布时间】:2016-02-26 07:26:47
【问题描述】:

OpenCart 2.0.3.1

问题 #1:在管理员中,尝试在多个选项卡中编辑多个项目通常会导致错误消息“无效的令牌会话,请重新登录”。

问题 #2:此错误消息似乎是随机发生的;我似乎无法确定“超时”。

问题 #3:点击“保存”后出现错误消息,这意味着所有更改都丢失了。我打开了许多带有复杂更改的选项卡,我想知道是否有可能以某种方式将令牌会话“恢复”到 URL 中,以便我可以实际保存它们。

【问题讨论】:

  • 仅当令牌和会话令牌不匹配时,Opencart 才会将管理员重定向到登录页面。
  • 同意 Ved Pandya,您确定您正在使用的所有这些选项卡都属于同一个会话吗?如果您重新登录其中一个选项卡,您所描述的将会发生。

标签: php session opencart token


【解决方案1】:

我写了一个 vQmod 脚本来让我在管理选项卡打开时保持登录状态。随意使用它。 :)

<?xml version="1.0" encoding="UTF-8"?>
<modification>
    <id>Keep Admin Users Logged In - Opencart 2.x</id>
    <version>1.0</version>
    <vqmver>2.5.1</vqmver>
    <author>Tibor Besze</author>

    <file name="admin/controller/user/user.php">
        <operation error="skip">
            <search position="after"><![CDATA[class ControllerUserUser extends Controller {]]></search>
            <add trim="true"><![CDATA[
                public function pingUser() {
                    $this->response->addHeader('Content-Type: application/json');
                    $this->response->setOutput(json_encode(1));
                }
            ]]></add>
        </operation>
    </file>
    <file name="admin/controller/common/footer.php">
        <operation error="skip">
            <search position="before"><![CDATA[return $this->load->view('common/footer.tpl', $data);]]></search>
            <add trim="true"><![CDATA[
                if (isset($this->session->data['token'])) {
                    $data['token'] = $this->session->data['token'];
                }
            ]]></add>
        </operation>
    </file>
    <file name="admin/view/template/common/footer.tpl">
        <operation error="skip">
            <search position="before"><![CDATA[</body>]]></search>
            <add trim="true"><![CDATA[
              <?php if (isset($token)) { ?>
              <script type="text/javascript">
                $(document).ready(function() {
                  setInterval(function() {
                    $.ajax({
                      type: "POST",
                      url: "index.php?route=user/user/pingUser&token=<?php echo $token; ?>",
                      dataType: "json",
                      timeout: 10000
                    });
                  }, 15000);
                });
              </script>
              <?php } ?>
            ]]></add>
        </operation>
    </file>
</modification>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    • 1970-01-01
    • 2013-06-29
    • 2012-12-10
    • 2021-03-24
    • 2014-08-22
    • 1970-01-01
    相关资源
    最近更新 更多