Joomla mod_login使用get用户名重定向 [英] Joomla mod_login redirect using get username

查看:125
本文介绍了Joomla mod_login使用get用户名重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Joomla 3构建网站,并希望每个唯一用户在从首页登录时将其重定向到特定页面.例如,当他们在登录表单中输入详细信息并单击提交时,它将使用URL index.php/ username

I am building a site using Joomla 3 and would like to redirect each unique user to a specific page when they login from the homepage. For example when they enter their details into the login form and click submit it redirects them to their page with the URL index.php/username

我已经找到了 mod_login/helper.php 文件,但是我不具备有关如何对其进行编辑的PHP知识.

I have found the mod_login/helper.php file but I have no PHP knowledge of how to edit it.

如何使用PHP将它们重定向到特定页面?

How can I redirect them to a specific page using PHP?

以下代码是 mod_login/helper.php 文件

<?php
/**
 * @package     Joomla.Site
 * @subpackage  mod_login
 *
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

/**
 * Helper for mod_login
 *
 * @package     Joomla.Site
 * @subpackage  mod_login
 * @since       1.5
 */
class ModLoginHelper
{
    public static function getReturnURL($params, $type)
    {
        $app    = JFactory::getApplication();
        $router = $app->getRouter();
        $url = null;
        if ($itemid = $params->get($type))
        {
            $db     = JFactory::getDbo();
            $query  = $db->getQuery(true)
                ->select($db->quoteName('link'))
                ->from($db->quoteName('#__menu'))
                ->where($db->quoteName('published') . '=1')
                ->where($db->quoteName('id') . '=' . $db->quote($itemid));

            $db->setQuery($query);
            if ($link = $db->loadResult())
            {
                if ($router->getMode() == JROUTER_MODE_SEF)
                {
                    $url = 'index.php?Itemid='.$itemid;
                }
                else {
                    $url = $link.'&Itemid='.$itemid;
                }
            }
        }
        if (!$url)
        {
            // Stay on the same page
            $uri = clone JURI::getInstance();
            $vars = $router->parse($uri);
            unset($vars['lang']);
            if ($router->getMode() == JROUTER_MODE_SEF)
            {
                if (isset($vars['Itemid']))
                {
                    $itemid = $vars['Itemid'];
                    $menu = $app->getMenu();
                    $item = $menu->getItem($itemid);
                    unset($vars['Itemid']);
                    if (isset($item) && $vars == $item->query)
                    {
                        $url = 'index.php/?Itemid='.$itemid;

                    }
                    else {
                        $url = 'index.php?'.JURI::buildQuery($vars).'&Itemid='.$itemid;
                    }
                }
                else
                {
                    $url = 'index.php?'.JURI::buildQuery($vars);
                }
            }
            else
            {
                $url = 'index.php?'.JURI::buildQuery($vars);
            }
        }

        return base64_encode($url);
    }

    public static function getType()
    {
        $user = JFactory::getUser();
        return (!$user->get('guest')) ? 'logout' : 'login';
    }
}

推荐答案

一个快速修复程序,可从菜单项ID重定向到任何特定页面,或保持在同一页面上.

A quick ugly fix to redirect to any specific page, or to stay on the same page, from the menu item id.

在文件模块/mod_login/helper.php中,使用默认的joomla登录模块,在类ModLoginHelper中,使用getReturnURL函数.

In the file modules/mod_login/helper.php, class ModLoginHelper, function getReturnURL, using the default joomla login module.

Joomla! 3.2.3使用EasyPHP稳定(PHP 5.3.5 MySQL 5.1.54-community)

Joomla! 3.2.3 Stable, with EasyPHP (PHP 5.3.5 MySQL 5.1.54-community)

我希望这会有所帮助,因为一些人对此丢失的conf选项遇到了/正在遇到问题.

I hope this helps, as a few people had/are having problems with this missing conf option.

经过快速测试,可靠性不高,[PHP的新手]

Quickly tested, not much reliability, [anew newbie to PHP]

class ModLoginHelper
{
    public static function getReturnURL($params, $type)
    {
        $app    = JFactory::getApplication();
        $router = $app->getRouter();
        $url = null;

         // JT.add:stay on same page (quickfix)
        $stayOnSamePage = false;
        if ($itemid = $params->get($type))
        {
            if($vars['Itemid'] == 101) 
                        // 101 = site default page, to get from the Menu Manager
                        // Can get it programmatically? Worth the fix?
                        // assuming you set the redirect page in the Login module to the site default one
            {
                // stay on the same page
                $stayOnSamePage = true;
            }
        }
        // endOf JT.add: stay on same page


        //JT.rm: if ($itemid = $params->get($type))
        if (($itemid = $params->get($type)) & !$stayOnSamePage) //JT.add
        {

这篇关于Joomla mod_login使用get用户名重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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