복붙노트

"경고 : 헤더 정보를 수정할 수 없습니다 - 이미 보낸 헤더"error [duplicate]

PHP

"경고 : 헤더 정보를 수정할 수 없습니다 - 이미 보낸 헤더"error [duplicate]

양식 삭제 양식을 제출하려고 할 때마다이 오류가 계속 발생합니다.

내 코드에 문제가 있습니까? 작동하도록 변경하려면 무엇이 필요합니까?

<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) { 
  // For security, start by assuming the visitor is NOT authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Session variable MM_Username set equal to their username. 
  // Therefore, we know that a user is NOT logged in if that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access to only certain users based on an ID established when they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>

<?php
    require_once('Connections/speedycms.php');

    $client_id = mysql_real_escape_string($_GET['id']); 

    $con = mysql_connect($hostname_speedycms, $username_speedycms, $password_speedycms);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("speedycms") or die(mysql_error());
?>

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

if ((isset($_GET['id'])) && ($_GET['id'] != "") && (isset($_POST['deleteForm']))) {
  $deleteSQL = sprintf("DELETE FROM tbl_accident WHERE id=%s",
                       GetSQLValueString($_GET['id'], "int"));

  mysql_select_db($database_speedycms, $speedycms);
  $Result1 = mysql_query($deleteSQL, $speedycms) or die(mysql_error());

  $deleteGoTo = "progress.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
    $deleteGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $deleteGoTo));
}

mysql_select_db($database_speedycms, $speedycms);
$query_delete = "SELECT * FROM tbl_accident  WHERE id=$client_id";
$delete = mysql_query($query_delete, $speedycms) or die(mysql_error());
$row_delete = mysql_fetch_assoc($delete);
$totalRows_delete = mysql_num_rows($delete);
?>

<p class="form2">Are you sure you wish to <b>delete</b> the record for <?php echo $row_delete['clientName']; ?>?</p>
                <form name="form" method="POST" action="<?php echo $deleteAction; ?>">
            <p class="form2"><input type="submit" value="Yes" />
              <input name="no" type="button" id="no" value="No" />
            </p>
                              <input type="hidden" name="deleteForm" value="form" />
        </form>     

미리 감사드립니다!

해결법

  1. ==============================

    1.45-47 행 :

    45-47 행 :

    ?>
    
    <?php
    

    출력으로 두개의 개행 문자를 보내므로 헤더가 이미 전달됩니다. PHP 코드를 끝내고 다시 시작해야하는 번거 로움이없는 3 행을 모두 제거하십시오. 60-62 행의 유사한 블록을 제거하면됩니다.

    실제로 얻은 오류 메시지는 직접 찾을 수있는 많은 정보를 제공합니다.

    두 개의 굵게 표시된 섹션은 항목이 머리글 (줄 47) 앞에 출력 된 곳과 항목이 출력 후 머리글을 보내려고했던 곳 (줄 106)을 알려줍니다.

  2. ==============================

    2.이것은 일반적으로 세션을 시작하기 전에 스크립트에서 의도하지 않은 결과가있을 때 발생합니다. 현재 코드를 사용하면 출력 버퍼링을 사용하여이를 해결할 수 있습니다.

    이것은 일반적으로 세션을 시작하기 전에 스크립트에서 의도하지 않은 결과가있을 때 발생합니다. 현재 코드를 사용하면 출력 버퍼링을 사용하여이를 해결할 수 있습니다.

    ob_start () 호출을 추가하십시오. 스크립트의 맨 위에있는 함수와 ob_end_flush (); 문서의 끝에.

  3. ==============================

    3.문서 인코딩을 확인하십시오.

    문서 인코딩을 확인하십시오.

    나는이 같은 문제가 있었다. Windows XP에서 Notepad ++ 및 WampServer를 사용하여 Apache를 로컬에서 실행하고 모두 괜찮 았습니다. Unix에서 Apache를 사용하는 호스팅 제공 업체에 업로드 한 후이 오류가 발생했습니다. 닫는 태그 다음에 여분의 PHP 태그 또는 공백이 없습니다.

    나에게 이것은 텍스트 문서의 인코딩 때문이었습니다. 메모장 ++ (인코딩 탭 아래)에서 "BOM없이 UTF-8로 변환"옵션을 사용하고 웹 서버에 다시로드했습니다. 문제가 해결되었으므로 코드 / 편집 변경이 필요하지 않습니다.

  4. ==============================

    4.?> 태그와

    ?> 태그와

    첫 번째 메시지가 전송되면 헤더가 먼저 전송됩니다.

    그런 일이 발생하면 더 이상 헤더를 수정할 수 없습니다.

    불필요한 태그를 제거하고 하나의 커다란

  5. ==============================

    5.PHP 태그 바깥에 공백 문자가있을 가능성이 있습니다.

    PHP 태그 바깥에 공백 문자가있을 가능성이 있습니다.

  6. ==============================

    6.이 링크를 확인하십시오 :

    이 링크를 확인하십시오 :

  7. from https://stackoverflow.com/questions/1912029/warning-cannot-modify-header-information-headers-already-sent-by-error by cc-by-sa and MIT license