是否可以要求登录OpenCart信息页面,而仅该信息页面? [英] Is it possible to require a login for an OpenCart Information page, and ONLY the information page?

查看:64
本文介绍了是否可以要求登录OpenCart信息页面,而仅该信息页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到许多扩展名使您可以在查看产品等之前登录,但我只想限制对通过创建新信息页面创建的特定页面的访问.这可能吗?我也不是很精通php,所以请告诉我应该编辑哪些文件以及在哪里.预先感谢.

I see many extensions that make you log in before viewing the products and such, but I only want to restrict access to a certain page that I created by creating a new information page. Is this possible? I am also not very proficient with php so please tell me which files I should be editing and where. Thanks in advance.

推荐答案

尝试将其添加到 index()之后的 controller/information/information.php 顶部>函数声明,并将{ID}替换为您要用密码保护的页面的ID(您可以从URL中获取ID,或者,如果有SEO URL,则可以从管理部分获取ID).

Try adding this at the top of controller/information/information.php straight after the index() function declaration and replace {ID} with the ID of the page you want to password protect (you can get the ID from the URL, or if you have SEO URLs, from the admin section).

if (isset($this->request->get['information_id']) && $this->request->get['information_id'] == '{ID}') {
    //If the information_id is provided and it matches the ID you wish to protect
    if (!$this->customer->isLogged()) {
        //If the customer is not logged in already, redirect them to the login page
        //Use $this->session->data['redirect'] to redirect them back to this page after logging in
        $this->session->data['redirect'] = $this->url->link('information/information', 'information_id=' . $this->request->get['information_id']);
        //Do the redirect
        $this->redirect($this->url->link('account/login', '', 'SSL'));
    }
}

在上面的示例中,我假定信息页面使用SSL,如果需要,则需要对其进行修改.

I've assumed that the information page is not using SSL in the above example, you'll need to modify it if it is.

如果您对应该去哪里感到困惑,请查看 controller/account/account.php -我从那里获取了这段代码,并针对特定信息对其进行了修改.页面.

If you're getting confused as to where this should go, have a look at controller/account/account.php - i've taken this code from there and modified it for a specific information page.

这篇关于是否可以要求登录OpenCart信息页面,而仅该信息页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆