CodeIgniter Forums

Full Version: how to redirect to different user pages
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]rangana[/eluser]
hi guys!

I'm developing a login, i need to login users and redirect them to their relevant interfaces
after validating the user, i can't understand how to redirect them to their respective interfaces in CI, how to do that? can you please help me out? if you can give a code and tell the answer it would be great...!

regards,
Rangana

El Forum

[eluser]intractve[/eluser]
If you have different user classes, eg: 1,2,3,4,5
You can do a switch case after login is successful and use CI's redirect() function to send them where ever you want.
The redirect function is part of the url helper, so be sure to load/autoload it.

El Forum

[eluser]rangana[/eluser]
got the idea, thank you George!

El Forum

[eluser]Vheissu[/eluser]
The way I go about this is to first log them in and then set all of their relevant information in a session, usually called user_role and then put if they're an admin or user in there. Then I redirect them to the index function of my Auth controller and inside of that Auth controller index function I am checking if they're an admin or user.

Code:
class Auth extends Controller {
    
    function Auth()
    {
        parent:Controller();
        // Load libraries here etc
    }

    function index()
    {
        // Check if they're an admin or user and use redirect() to send them to their respective places
    }


}

El Forum

[eluser]natedigby[/eluser]
[quote author="intractve" date="1281303683"]If you have different user classes, eg: 1,2,3,4,5
You can do a switch case after login is successful and use CI's redirect() function to send them where ever you want. The redirect function is part of the url helper, so be sure to load/autoload it.[/quote]

Hi George,

I have same issue with TS. I understood these directions and made sure to load/autoload it, but I'm still having the same problem.

What do you think is the problem?

Regards,

El Forum

[eluser]intractve[/eluser]
I cannot say what the problem is unless I know the setup you are running this in.

The redirect() function is something I use extensively and have had zero problems with it so far.
If you can post a bit of code where you are using it I can probably help better.

Just to be helpful to anyone who is reading this thread for help on redirect()

Usage of Redirect

Code:
//To redirect to the user controller
redirect('/user');
//NOT $this->redirect();
//Made this mistake when I first used CI

El Forum

[eluser]natedigby[/eluser]
Hi George,
Thanks for the reply.

I really don't what seemed to be the problem but when I used the code:

Code:
redirect('/user');

you provided and the redirect function worked. Any way I don't want to go further into details with why it wasn't functioning last time. I'm fine with this now.

Many thanks for the help.

El Forum

[eluser]intractve[/eluser]
No Problem, Have fun.