0
votes

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /srv/disk5/1241421/www/ebazzar.co.nf/application/models/product_model.php:2)

Filename: libraries/Session.php

Line Number: 672

...

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /srv/disk5/1241421/www/ebazzar.co.nf/application/models/product_model.php:2)

Filename: helpers/url_helper.php

Line Number: 542

How can I solve this error? It appears when add some content in the database

function goes like this:

public function signup() {
    if ($this->authex->logged_in()) {
        redirect('welcome');
    }
    //$data['page'] = $this->uri->segment(2);
    $data['fproducts'] = $this->pm->get_fproducts();
    $data['countries'] = $this->pm->get_countries();
    if ($this->input->post('submit_signup')) {
        if ($this->_form_validate() == FALSE) {
            $this->load->view('header', $data);
            $this->load->view('sidebar');
            $this->load->view('signup');
            $this->load->view('footer');
        } else {
            $signup_id = $this->pm->add_user();
            if ($signup_id) {
                $this->session->set_flashdata('message', array('title' => 'Signup Result', 'content' => 'You have been successfully registered', 'type' => 'message'));

                redirect("welcome/home");
            }
        }
    } else {
        $this->load->view('header', $data);
        $this->load->view('sidebar');
        $this->load->view('signup');
        $this->load->view('footer');
    }
}
1
Seems there is some output before the session is started, you can check what those extra output is. Probably an error, notice or something you added. - Daniel Cheng
but it absolutely works well in localhost and i guess i shouldn't mess with codeigniter framework and its session library - madhav acharya
pls post the fn that produce error - open source guy
ebazzar.co.nf and these errors appears in signup.. but the data are inserted in database even with the errors - madhav acharya
Try to disable all error. I mean that change to production mode! - Raja

1 Answers

0
votes

Supposing that your redirect function is using the PHP header function, the problem is this:

The header function is supposed to be called before any output otherwise it will not work. You are obviously outputting something else before calling that function.

Rearrange your code so that the output is printed at the end of the file, or use the ob_* functions family to control the output buffer.

Notice that to fix the problem the error is also telling you where the invalid output, before the header call, is started:

output started at /srv/disk5/1241421/www/ebazzar.co.nf/application/models/product_model.php:2