Joomla mod_login使用get username重定向

时间:2013-09-20 02:17:20

标签: php redirect joomla login username

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

我找到了 mod_login / helper.php 文件,但我对如何编辑它没有PHP知识。

如何使用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';
    }
}

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

试试这个,

从您可以使用的任何页面成功登录joomla后重定向

<input type="hidden" name="return" value="<?php echo base64_encode("your return url"); ?>" />

此隐藏字段应在您的登录表单中找到,如下所示。

<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post">

        <fieldset>
            <?php foreach ($this->form->getFieldset('credentials') as $field): ?>
                <?php if (!$field->hidden): ?>
                    <div class="login-fields"><?php echo $field->label; ?>
                    <?php echo $field->input; ?></div>
                <?php endif; ?>
            <?php endforeach; ?>
            <button type="submit" class="button"><?php echo JText::_('JLOGIN'); ?></button>
            <input type="hidden" name="return" value="<?php echo base64_encode($this->params->get('login_redirect_url',$this->form->getValue('return'))); ?>" />
            <?php echo JHtml::_('form.token'); ?>
        </fieldset>
    </form>

你只需要将你的返回网址放在隐藏字段中,使用base64_encoded joomla会在登录成功时重定向到此网址。

希望它的帮助...

答案 2 :(得分:0)

快速丑陋的修复,可以从菜单项ID重定向到任何特定页面,或保持在同一页面上。

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

的Joomla! 3.2.3使用EasyPHP稳定(PHP 5.3.5 MySQL 5.1.54社区)

我希望这会有所帮助,因为有些人在使用这个缺失的conf选项时遇到了问题。

快速测试,可靠性不高,[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
        {