如何修复错误无法修改标头信息 - 已发送的标头

问题描述:

我在codeigniter中有以下类型的错误,我无法解决它任何人都知道这个错误的原因是什么。
如何修复错误无法修改标头信息 - 已发送的标头

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 

我采用两种方法都是在相同控制器用作波纹管。

<?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'); 
    } 
} ?> 

在执行这个函数后,我重定向了另一个方法,如下所示。

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

我检查了url_helper,在行号540这个代码是有'case'的情况'\t:header(“Refresh:0; url =”。$ uri); – sangam 2014-10-11 05:32:37

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) 

的错误,当你已经开始输出什么头之前重定向PHP代码中出现。 例如,检查PHP标记之前或之后的任何空格,在启动PHP标记之前打印HTML标记,或者在重定向函数之前输出任何输出或调试。

如果您仍然遇到问题,请让我知道更多。

+0

谢谢,我发现错误在哪里,我的关闭php标签后有一些空行,我删除它,然后它工作正常。 – sangam 2014-10-11 05:46:36

+0

对不起,我忘了标记它。 – sangam 2014-10-11 09:53:47

+0

@sangam谢谢。 – 2014-10-11 09:55:19

用它代替重定向。 echo'window.location =''。base_url()。'your-page-name';';

+0

不要这样做。它打破了后退按钮。 – Quentin 2017-05-02 15:51:55