无法修改标头输出已启动警告
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法修改标头输出已启动警告相关的知识,希望对你有一定的参考价值。
所以我收到这个错误:
警告:无法修改标头信息 - 已在第55行的/Applications/MAMP/htdocs/add_user.php中发送的标头(在/Applications/MAMP/htdocs/add_user.php:50处开始输出)
第55行的代码是:
55 header(sprintf("Location: %s", $insertGoTo));
脚本开始于:
<?php require_once('Connections/connHotel.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING']))
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "userform"))
$insertSQL = sprintf("INSERT INTO clients (title, firstName, lastName, address1, address2, town, province, country, postCode, telephone, email) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['title'], "text"),
GetSQLValueString($_POST['firstName'], "text"),
GetSQLValueString($_POST['lastName'], "text"),
GetSQLValueString($_POST['address1'], "text"),
GetSQLValueString($_POST['address2'], "text"),
GetSQLValueString($_POST['town'], "text"),
GetSQLValueString($_POST['province'], "text"),
GetSQLValueString($_POST['country'], "text"),
GetSQLValueString($_POST['postcode'], "text"),
GetSQLValueString($_POST['telephone'], "text"),
GetSQLValueString($_POST['email'], "text"));
mysqli_select_db($connHotel, $database_connHotel);
$Result1 = mysqli_query($connHotel, $insertSQL) or die(mysqli_error($connHotel));
$insertGoTo = "booking_details.php?email=$email";
if (isset($_SERVER['QUERY_STRING']))
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
我不明白警告的含义。
答案
必须在所有其他输出之前发送标头。确保在此之前不发送任何其他字符。即使你的PHP开场序列<?php
也不能有任何前导字符。
以上是关于无法修改标头输出已启动警告的主要内容,如果未能解决你的问题,请参考以下文章