Welcome Guest, Not a member yet? Register   Sign In
redirect error with maintenance mode my controller
#1

(This post was last modified: 02-04-2016, 11:26 PM by wolfgang1983.)

I am working on my redirection for my maintenance mode but have run in to a snag.

Each controller extends MY_Controller.

On MY_Controller.php I have a function called maintenance_mode() which if is TRUE will redirect to the maintenance controller OK.

What I am hoping is if maintenance mode is TRUE but then if I am logged to admin will let me view website once redirected home controller.

It redirects to home url but then throws firefox error


Code:
The page isn't redirecting properly


Any suggestion on solution.


PHP Code:
<?php

class MY_Controller extends CI_Controller {
    
    public function 
__construct() {
        
parent::__construct();
        
$this->maintenance_mode();
    }

    public function 
maintenance_mode() {

        
$this->load->library('user');

        if (
config_item('maintenance') && $this->user->is_logged_in()) {
            
 
                       // Testing message only will be removed
            
echo "Admin Logged In";
            
redirect(base_url());
        
        } else {

 
                       // Testing message only will be removed
            
echo "Admin Not Logged In";

            
$route 'd=' $this->input->get('d') .'&c='$this->input->get('c');

            
$ignore = array(
                
'd=common&c=maintenance'
            
);

            if (!
in_array($route$ignore) && config_item('maintenance')) {
                
redirect('d=common&c=maintenance');
            } 

        }
        
    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

not echo before header function ( redirect ).

$this->session->setflashdata('key', 'blah blah blah blah');
redirect(base_url());

In view for base_url():
echo $this->session->flashdata('key');
Reply
#3

(This post was last modified: 02-04-2016, 11:20 PM by wolfgang1983.)

(02-04-2016, 11:18 PM)nhatkontum Wrote: not echo before header function ( redirect ).

$this->session->setflashdata('key', 'blah blah blah blah');
redirect(base_url());

In view for base_url():
echo $this->session->flashdata('key');

It has nothing to do with session or flashdata
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

Did you try doing a redirect using ( location / refresh ) ?
What did you Try? What did you Get? What did you Expect?

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

A "The page isn't redirecting properly" error is shown when the browser detects you are in a redirect loop.
Reply
#6

(02-05-2016, 05:46 AM)InsiteFX Wrote: Did you try doing a redirect using ( location / refresh ) ?

I think I have now got it working Have I set MY_Controller up correct any changes you would recommend.

PHP Code:
<?php

class MY_Controller extends CI_Controller {
    
    public function 
__construct() {
        
parent::__construct();
        
$this->load->library('user');
        
$this->maintenance_mode();
    }

    public function 
maintenance_mode() {

        if (
config_item('maintenance') && $this->user->is_logged_in()) {
        
            return 
TRUE;
        
        } else {

            if (
config_item('maintenance') == 1) {

                
$route 'd=' $this->input->get('d') .'&c='$this->input->get('c');

                
$ignore = array(
                    
'd=common&c=maintenance'
                
);

                if (!
in_array($route$ignore)) {
                    
redirect('d=common&c=maintenance');
                } 

            } else {

                return 
0;
            }
        }
    }



Maintenance Controller

PHP Code:
<?php

class Maintenance extends MY_Controller {

    public function 
__construct() {
        
parent::__construct();
        
$this->load->library('position');
        
$this->load->library('user');
    }

    public function 
index() {

        if (
config_item('maintenance')) {

        if (
$this->user->is_logged_in()) {
            
redirect(base_url());
        }

        
$this->data['title'] = 'Maintenance';

        
$this->data['column_left'] = $this->position->choose('column_left');
        
$this->data['column_right'] = $this->position->choose('column_right');
        
$this->data['content_top'] = $this->position->choose('content_top');
        
$this->data['content_bottom'] = $this->position->choose('content_bottom');

        
$this->load->view('theme/default/template/common/header_view'$this->data);
        
$this->load->view('theme/default/template/common/maintenance_view'$this->data);
        
$this->load->view('theme/default/template/common/footer_view'$this->data);

        } else {

            
redirect('d=common&c=home');
        }

    }

There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB