“警告:无法修改标头信息-已由标头发送的标头"错误 [英] "Warning: Cannot modify header information - headers already sent by" error

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

问题描述

可能重复:
PHP已发送的标头

Possible Duplicate:
Headers already sent by PHP

每次尝试提交表单删除表单时,我都会不断收到此错误.

i keep receiving this error each time i try to submit the a form deletion form.

警告:无法修改标题 信息-标头已由发送 (输出开始于 C:\ xampp \ htdocs \ speedycms \ deleteclient.php:47) 在 C:\ xampp \ htdocs \ speedycms \ deleteclient.php 在第106行

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\speedycms\deleteclient.php:47) in C:\xampp\htdocs\speedycms\deleteclient.php on line 106

我的代码有问题吗?我需要进行哪些更改才能使其正常工作?

is there something wrong with my code? what do i need to change to make it work?

<?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>     

先谢谢您!

推荐答案

第45-47行:

?>

<?php

这将发送一些换行符作为输出,因此标头已经被分派.只需删除这3行(毕竟这是一个很大的PHP块,不需要结束PHP解析然后再次启动它),以及第60-62行的类似块,就可以了.

That's sending a couple of newlines as output, so the headers are already dispatched. Just remove those 3 lines (it's all one big PHP block after all, no need to end PHP parsing and then start it again), as well as the similar block on lines 60-62, and it'll work.

请注意,您收到的错误消息实际上为您提供了很多信息,可以帮助您自己找到此错误:

Notice that the error message you got actually gives you a lot of information to help you find this yourself:

警告:无法修改标题 信息-标头已由发送 (输出始于 C:\ xampp \ htdocs \ speedycms \ deleteclient.php:47 ) 在 C:\ xampp \ htdocs \ speedycms \ deleteclient.php 在第106行

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\speedycms\deleteclient.php:47) in C:\xampp\htdocs\speedycms\deleteclient.php on line 106

两个加粗的部分告诉您项目是在标题之前发送输出的位置(第47行)以及项目在输出之后试图发送标题的位置(行106).

The two bolded sections tell you where the item is that sent output before the headers (line 47) and where the item is that was trying to send a header after output (line 106).

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

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