Welcome Guest, Not a member yet? Register   Sign In
ERR_TOO_MANY_REDIRECTS
#1

Hello,

I use codeigniter 3 and I'm trying to prevent an unregistered user from accessing any function of a controller. To do this in the contructor I check if the session variable "name" is defined and if it is not I do a "redirect" to the base_url().

If this variable is not defined I redirect with "redirect" to the base_url. But what I get is an error: "ERR_TOO_MANY_REDIRECTS".

Code:
class inicio extends CI_Controller
    {

        function __construct()
        {
            parent::__construct();
            $this->load->model("usuarios_modelo");


            if(!$this->session->userdata("nombre"))
            {

                    redirect(base_url());

            }
        }

My htaccess is:

Code:
#<IfModule mod_rewrite.c>

# RewriteEngine on
# RewriteCond $1 !^(index\.php)
# RewriteRule ^(.*)$ index.php/$1 [L]

#</IfModule>

<IfModule mod_rewrite.c>

# allow_override On
# mod_rewrite is installed

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

<IfModule mod_php5.c>
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

<IfModule !mod_php5.c>
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

</IfModule>


Can you hel me?

Thanks
Reply
#2

(This post was last modified: 09-16-2018, 09:10 AM by InsiteFX.)

That's because the way you are doing it is sending your controller into a never ending loop.

Send them to an error page or something else.

IF it is a login auth system then check to see if they are logged in and if not send them to your login page.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

(09-16-2018, 09:08 AM)InsiteFX Wrote: That's because the way you are doing it is sending your controller into a never ending loop.

Send them to an error page or something else.

IF it is a login auth system then check to see if they are logged in and if not send them to your login page.

Ok. But how i do it? usin "redirect" again?

Thanks
Reply
#4

It's hard to try and help you when you do not give us the information we need.

What auth system are you using etc; ?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#5

(09-16-2018, 11:15 AM)InsiteFX Wrote: It's hard to try and help you when you do not give us the information we need.

What auth system are you using etc; ?

Thanks!!!

My sistem is CodeIgniter 3.1.9.

i think that if i use "redirect" i nte constructor fo de class i always get de same error. you say me to redirect to a view? like this?


Code:
class inicio extends CI_Controller
   {

       function __construct()
       {
           parent::__construct();
           $this->load->model("usuarios_modelo");


           if(!$this->session->userdata("nombre"))
           {

                   $this->load->view("mensaje");

           }
       }
Reply
#6

If it is an auth system then you would want them to be sent to a login view.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB