简体   繁体   中英

Cannot Modify Header Information Headers Already Sent

I know this question has been asked many times but I have seen so many different answers and have tried them all and none have worked for me. So let me provide you with my specific context, and see what you recommend:

I am developing on Mac OS X El Capitan. I am using PHP version 5.5.31. error message

I have output buffering turned on in my php.ini file. I have obsessively checked there is no white space before the header is sent. Here are the lines the code is referring to:

(edit_subject.php:6)

<?php require_once("../includes/session.php");?>
<?php require_once("../includes/db_connection.php");?>
<?php require_once("../includes/functions.php");?>
<?php require_once("../includes/validation_functions.php");?>
<?php find_selected_page();?> 
<?php 
if(!$current_subject){
**redirect_to("manage_content.php")**;
}
?>

(edit_subject.php:38)

$result = mysqli_query($connection, $query);
if ($result && mysqli_affected_rows($connection) >= 0) {
// Success
$_SESSION["message"] = "Subject edited succesfully.";
**redirect_to("Location: manage_content.php");**
} else {
// Failure
$message = "Subject update failed.";
}

(functions.php:3)

<?php
function redirect_to($new_location) {
redirect_to("Location: . $new_location");
exit;
?>

I've been pulling my hair out for the last 48 hours. I'd appreciate some guidance here.
Thanks, Chris

The following line is triggering the warning (functions.php line 3):

redirect_to("Location: . $new_location");

It is attempting to send headers, after something has already been output (probably another error/warning considering your syntax is broken). Check your error logs.

try flushing the buffer before redirecting. the problem arises if there is already something outputted and you try changing the header in this case by redirection.

You can use ob_start() at top, and ob_end_flush() to flush before changing the header.

Note: Flushing the buffer only hides the problem, its not the solution. There's some piece of bad practice of coding, try figure that out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM