• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect not working

#1
[eluser]webnology[/eluser]
Hi everyone,

I have a simple redirect in my code, which is simply not working. It gets on an empty, blank ,white page. Any idea what could be wrong?

Code:
redirect('/customers/dashboard', 'refresh');

Many thanks,
Michel

#2
[eluser]Xclamation Design[/eluser]
Hi Michael,

Could you possibly provide a little more code? Perhaps you could provide the code for your controller/model where you are calling the 'redirect' and also the controller for '/customers/dashboard'?

#3
[eluser]webnology[/eluser]
Hey Michael,

true. Here's some more info. It's the cotroller where I add the form to the db.

Code:
function addCustomer() {
    
            //Validate if user is logged in. If not load login view
            if ($this->tank_auth->is_logged_in()) {

                //Set validation rules
                $this->form_validation->set_rules('firstname', 'Voornaam', 'required');
                $this->form_validation->set_rules('lastname', 'Naam', 'required');
                $this->form_validation->set_rules('email', 'E-mail', 'required');    
                $this->form_validation->set_rules('birthday', 'Verjaardag dag', 'required');    
                $this->form_validation->set_rules('birthmonth', 'Verjaardag maand', 'required');    

                //Load views with data depending on error or success
                if ($this->form_validation->run() == FALSE) {

                    //General info for the page
                    $data['title'] = 'Klant toevoegen';
                    $data['user_is_logged_in'] = $this->tank_auth->is_logged_in();
                    
                    //Load form view for adding a customer
                    $this->load->view('v_addcustomer', $data);
                }
                
                else {

                    //Add data to the tables
                    $formdata = array(
                        'lastname' => $this->input->post('lastname'),
                        'firstname' => $this->input->post('firstname'),
                        'gender' => $this->input->post('gender'),
                        'birthday' => $this->input->post('birthday'),
                        'birthmonth' => $this->input->post('birthmonth'),
                        'address' => $this->input->post('address'),
                        'postalcode' => $this->input->post('postalcode'),                    
                        'city' => $this->input->post('city'),                                        
                        'mobnr' => $this->input->post('mobnr'),                                        
                        'fixednr' => $this->input->post('fixednr'),
                        'email' => $this->input->post('email'),                    
                        'memo' => $this->input->post('memo'),                                            
                        'flag_sms' => $this->input->post('flag_sms'),                                            
                        'flag_email' => $this->input->post('flag_email')
                        );

                        $this->db->set('user_id', $this->tank_auth->get_user_id());
                        $this->db->insert('customers', $formdata);

                        //Redirect to success page
                        redirect('/customers/dashboard/');
                }
            
            }
            
            //User is logged out
            else {
            
                //General info for the page
                $data['user_is_logged_in'] = FALSE;
    
                //User needs to be logged in, redirect to login page
                $data['show_captcha'] = FALSE;
                
                //Add 1 in the 3rd segment to show that the user wants to add a band.
                redirect('/auth/login/');
            }
        }


I also get these 2 errors:

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /var/www/html/system/core/Exceptions.php:170)
Filename: libraries/Session.php
Line Number: 671

A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at /var/www/html/system/core/Exceptions.php:170)
Filename: helpers/url_helper.php
Line Number: 543

All help appreciated,
Michel

#4
[eluser]Xclamation Design[/eluser]
Hi Michael,

The error you are getting is a common one and suggest that something is being printed/echoed to screen before the redirect takes place. This is why you are getting the message 'Cannot modify header information'. This may be in another controller/method/function somewhere before where you call the 'store user function'.

Let us know how you get on or if you require any further help.

Regards,

#5
[eluser]boltsabre[/eluser]
yeah, as Xclamation Design has said, you're printing/echo'ing something somewhere. I often get this message during development, often I have a print_r statement in my model where I've been checking output from the DB, that I've forgotten to delete.

#6
[eluser]webnology[/eluser]
ok, thx guys for the help. I still had sth in my index.php file for date outputting. Forgot about that. :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.