how to fix error Cannot modify header information - headers already sent by [duplicate]

牧云@^-^@ 提交于 2020-06-27 16:30:32

问题


I have following type of error in codeigniter, I am unable solve it any one have idea what is cause of this error.

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at    /home/samples1/public_html/venture-test/application/controllers/admin/admin_notifications.php:158)

Filename: helpers/url_helper.php

Line Number: 540

I used two methods both are in same controllers as bellow.

 <?php
    public function approve_recent_user() {  
    $user_id = $this->uri->segment(4);
    $notification_id = $this->uri->segment(5);
    $status = 1;
    if($this->admin_notification_db->user_approve_flag($user_id,$status) == true) {
     redirect('admin/admin_notifications/unapproved_users');                
    }
    else {
        redirect('admin/admin_home');
    }
} ?>

after execution of this function I redirect on fo another methods as bellow.

<?php 
 public function unapproved_users() {        
    $result = $this->admin_notification_db->get_unapproved_users();
    $data['users'] = $result; 
    $this->load->view('admin/recent_users', $data); 
 } ?>

回答1:


Message: Cannot modify header information - headers already sent by (output started at    /home/samples1/public_html/venture-test/application/controllers/admin/admin_notifications.php:158)

The error occurs when you have started outputting anything before header redirect in PHP code. For example, check out any white spaces after or before PHP tags, HTML tags printing before starting of PHP tags or any output or debugging before the redirect function.

Please let me know further if you are still getting issues.




回答2:


use this instead for redirect. echo 'window.location="'.base_url().'your-page-name";';



来源:https://stackoverflow.com/questions/26311400/how-to-fix-error-cannot-modify-header-information-headers-already-sent-by

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!