如何修复错误无法修改标头信息 - 标头已发送 [英] how to fix error Cannot modify header information - headers already sent by

查看:46
本文介绍了如何修复错误无法修改标头信息 - 标头已发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 codeigniter 中有以下类型的错误,我无法解决任何人知道此错误的原因.

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

推荐答案

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 标记或重定向功能之前的任何输出或调试.

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.

这篇关于如何修复错误无法修改标头信息 - 标头已发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆