简体   繁体   English

Joomla 2.5主页重定向问题

[英]Joomla 2.5 home page redirect issue

I want to set joomla site to redirect visiting users to registration page if my cookie is not set. 如果未设置我的cookie我想设置joomla网站以将访问用户重定向到注册页面。 I've put below code in top of the (after imports) template index.php file. 我将下面的代码放在(导入后) template index.php文件的顶部。

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

URL is redirect but it is going in loop. URL是重定向的,但它正在循环中。 so page not loading correctly. 因此页面无法正确加载。 This is fire bug screen shot 这是萤火虫的屏幕截图 在此处输入图片说明

How to omit this loop ? 如何忽略此循环? Thanks. 谢谢。

Please check if the page you are redirecting to runs the piece of code you have mentioned in your question. 请检查您重定向到的页面是否运行您在问题中提到的代码段。

If so, you can use a placeholder cookie. 如果是这样,则可以使用占位符cookie。

Here is how: 方法如下:

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();
}

cause template index.php running on all pages and also on registration page so you need to set cookie values before redirect. 导致模板index.php在所有页面以及注册页面上都运行,因此您需要在重定向之前设置cookie值。 so it will be set on register page and you not redirect again 因此它将在注册页面上设置,并且您无需再次重定向

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

Your problem because of your code. 您的问题,因为您的代码。 You put your code on top of page... your redirection to registration page is correctly but when page goes to registration page.. at that time this code also check because it is on top of index file.. so again redirect on registration page. 您将代码放在页面顶部...重定向到注册页面是正确的,但是当页面转到注册页面..那时,此代码还会检查,因为它位于索引文件的顶部..因此再次在注册页面上重定向。

So, loop continue redirecting...then i think issue create. 因此,循环继续重定向...然后我认为问题产生了。

Put condition on your code with cookies like below, 使用如下所示的Cookie在代码中添加条件,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM