远程服务器错误 - 警告:无法修改标头信息 - 标头已发送


Remote server error - Warning: Cannot modify header information - headers already sent

我是 php 的新手,我一直在努力寻找远程服务器上此错误的解决方案,它在我的计算机上本地工作正常

Warning: Cannot modify header information - headers already sent by (output started at /home3/ezzuah/public_html/onecedishop.com/page.php:3) in /home3/folder_path/page.php on line 62

.php

<?php require_once('Connections/conn.php'); ?>
<?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;
}
}
$colname_rs_users = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_rs_users = $_SESSION['MM_Username'];
}
mysql_select_db($database_conn, $conn);
$query_rs_users = sprintf("SELECT * FROM regis WHERE username = %s", GetSQLValueString($colname_rs_users, "text"));
$rs_users = mysql_query($query_rs_users, $conn) or die(mysql_error());
$row_rs_users = mysql_fetch_assoc($rs_users);
$totalRows_rs_users = mysql_num_rows($rs_users);
?>
<?php

// Create connection
$conn= new mysqli($hostname_conn, $username_conn, $password_conn,$database_conn);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$user=$row_rs_users['username'];
$sql = "UPDATE regis SET credit_unit = credit_unit - 1  WHERE username='$user'";
if ($conn->query($sql) === TRUE) { 
} else {
    echo "Error updating record: " . $conn->error;
}
header("Location:bid_ok_m.php"); 
$conn->close();
?> 

<?php
mysql_free_result($rs_users);
?>

当我预览我的页面时,我收到我在网络上阅读的此错误,我被告知在脚本的开始和结束之前不应该有任何空格,我做了,但仍然收到错误

有多个实例可以关闭PHP标签,留下空格,然后再次开始PHP

例如:

    $totalRows_rs_users = mysql_num_rows($rs_users);
?>
    //<-- THERE IS WHITESPACE HERE!
<?php
删除

所有空格,或仅删除PHP标记的关闭/打开,以防止在标头之前发送输出。

这是因为您正在打开和关闭 php 标签。

它们之间有空格,被视为浏览器上的输出。

如果要使重定向起作用,则只需要有一个<?php开始标记。

建议您不要关闭?>标记。