Joomla 2.5主页重定向问题

时间:2014-04-11 06:24:57

标签: php redirect joomla joomla2.5

如果我的joomla未设置,我想设置cookie网站将访问用户重定向到注册页面。 我已将下面的代码放在(导入后)template index.php文件之后。

if (empty($_COOKIE["abc"])){   
    $app = &JFactory::getApplication();    
    $link = "index.php?option=com_users&view=registration";
    $app->redirect($link);
   exit();
}

网址是重定向的,但它是循环的。所以页面加载不正确。 这是火虫屏幕截图 enter image description here

如何省略此循环? 感谢。

3 个答案:

答案 0 :(得分:1)

请检查您要重定向的页面是否运行了您在问题中提到的代码段。

如果是这样,您可以使用占位符cookie。

以下是:

if (empty($_COOKIE["abc"]) && empty($_COOKIE['is_redirected'])){   
    $app = &JFactory::getApplication();    
    $link = "index.php?option=com_users&view=registration";
    setcookie("is_redirected", "true", time()+3600); // this will make sure that only one redirection happens
    $app->redirect($link);
   exit();
}

答案 1 :(得分:1)

导致模板index.php在所有页面上以及注册页面上运行,因此您需要在重定向之前设置cookie值。所以它将被设置在注册页面上,你不会再次重定向

if (empty($_COOKIE["abc"])){   
        $app = &JFactory::getApplication();    
        $link = "index.php?option=com_users&view=registration";
        setcookie("abc", "true", time()+3600);
        $app->redirect($link);
       exit();
    }

答案 2 :(得分:1)

你的问题是因为你的代码。你把你的代码放在页面顶部...你的重定向到注册页面是正确的,但是当页面进入注册页面时...那时这个代码也检查,因为它在索引文件的顶部..所以再次重定向注册页面

所以,循环继续重定向......然后我认为问题创建。

使用下面的Cookie为您的代码添加条件,

if (empty($_COOKIE["abc"]) && empty($_COOKIE['is_redirected']) && (new condition)){ 
  • 新条件:上面用check your page is not login or register what you want.
  • 替换新条件
相关问题