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

[eluser]pictwist[/eluser]
I was working with CodeIgniter 1.7.3 on my last project and to redirect i used this code

Code:
redirect('home/login');

and it worked well.
On my current project i am using CodeIgniter 2.0.2
Code:
redirect('home/login');

throws an error. for firefox:

The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept
cookies.


for chrome:
This webpage has a redirect loop
The webpage at http://localhost/mms/index.php/home/login has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Here are some suggestions:
Reload this web page later.
Learn more about this problem.
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.



Do you any idea what i could have done wrong?
I have loaded the 'url' helper in the config file.
#2

[eluser]toopay[/eluser]
How you put that code?
For me, it seems you should add some extra rules, which sorted only specific condition, before give redirect response.
#3

[eluser]pictwist[/eluser]
Could you highlight on the specifics of those 'extra rules'?
An exmple could help.
Thanks.
#4

[eluser]toopay[/eluser]
Post your 'home' controller..
#5

[eluser]pictwist[/eluser]
Please view the home controller.
This is the content

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
    
    public function __construct(){
        parent::__construct();
        $this->_isLoggedIn();
    }
    
    public function _isLoggedIn(){  
        if ($this->session->userdata('isloggedIn') == TRUE);
        else redirect('home/login');
    }
    
    public function validate_credentials(){
        // TODO: Validate login
    }

    public function index()
    {
        $this->load->view('home_page');
    }
    
    public function login(){
        $this->load->view('login');
    }
}
#6

[eluser]toopay[/eluser]
Based by your approach, maybe this would be better...
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
    
    public function __construct()
    {
        parent::__construct();
    }
    
    public function index()
    {
        $this->_isLoggedIn();
        $this->load->view('home_page');
    }
    
    public function login()
    {
        $this->load->view('login');
    }

    
    public function _isLoggedIn()
    {  
         // First, i think we must inspect, is there a specific session
         if($this->session->userdata('isloggedIn'))
         {
              if($this->session->userdata('isloggedIn') != TRUE)
              {
                   redirect('home/login');
              }
         }
         else
         {
              die('No Session Created!');
         }
    }
    
    public function validate_credentials()
    {
        // TODO: Validate login
    }
}
#7

[eluser]pictwist[/eluser]
I tried your approach and it works.
But i need to redirect to the login page.
How do you do the redirect?

I tried this but still get the same error.

Code:
public function _isLoggedIn()
    {  
         // First, i think we must inspect, is there a specific session
         if($this->session->userdata('isloggedIn'))
         {
              if($this->session->userdata('isloggedIn') != TRUE)
              {
                   redirect('home/login');
              }
         }
         else
         {
              //die('No Session Created!');
              redirect('home/login');
         }
    }
#8

[eluser]pictwist[/eluser]
I got a quick fix solution.
I moved the login function to its own controller.
This seems to work fine.
I shall try to find out why the other approach did not work.
#9

[eluser]toopay[/eluser]
The redirect function is not change at all, from v 1.7.x to 2.0.x

Why you uncomment this part...
Code:
//die('No Session Created!');
redirect('home/login');
#10

[eluser]pictwist[/eluser]
I commented it out because it kills the php script.
I needed the script to continue being executed.




Theme © iAndrew 2016 - Forum software by © MyBB