簡體   English   中英

Joomla mod_login使用獲取用戶名重定向

[英]Joomla mod_login redirect using get 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';
    }
}

嘗試這個,

在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>

您只需要將返回URL放在base64_encoded隱藏字段中即可,登錄成功后,joomla將重定向到該URL。

希望能有所幫助...

從菜單項ID重定向到任何特定頁面或停留在同一頁面上的快速丑陋修補程序

在文件模塊/mod_login/helper.php中,使用默認的joomla登錄模塊,將類ModLoginHelper用作函數getReturnURL。

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

我希望這會有所幫助,因為一些人對此丟失的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
        {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM