我已经看了很多修复这个我试过删除空白,但没有,我试过使用ob_start();功能但无济于事。无论我做什么,都会给我这个错误。警告:无法修改标头信息无法修复
警告:不能更改头信息 - 已经 发送的报头/home/gener105/public_html/includes/vault_post.inc.php(输出开始/home/gener105/public_html/header.php:37)上线12
它说输出开始在我的header.php文件的最后一行(图1),它有一个问题,我调用header();在我需要使用的函数中。这是因为我使用header();函数在vault_post.inc.php的第12行(图2)。
我只是困惑,为什么它这样做,因为theres在标题之前没有输出被调用。
FIG1(header.php文件)
<?php
session_start();
include 'includes/dbh.php';
include 'includes/vault_post.inc.php';
date_default_timezone_set('America/New_York');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Generation Diary - Leave Them Something For Later</title>
<!-- Bootstrap Core CSS -->
<link href="lib/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="lib/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Cabin:700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css">
<!-- Theme CSS -->
<link href="css/grayscale.min.css" rel="stylesheet">
<!-- Temporary navbar container fix until Bootstrap 4 is patched -->
<style>
.navbar-toggler {
z-index: 1;
}
@media (max-width: 576px) {
nav > .container {
width: 100%;
}
}
</style>
</head>
FIG2(vault_post.inc.php)在文件中多数民众赞成所需的第一功能
<?php
function setVaultPosts($conn) {
if (isset($_POST['vault_sub'])) {
$uid = $_POST['uid'];
$date = $_POST['date'];
$content = $_POST['content'];
$sql = "INSERT INTO vaults (uid, date0, content) VALUES ('$uid', '$date', '$content')";
$result = mysqli_query($conn, $sql);
header("Location: http://www.generationdiary.com/user_vault.php?success");
}
}
形成所需要的功能
<?php include('header.php'); ?>
<div class="container" id="vault_main">
<div class="row row-offcanvas row-offcanvas-right">
<div class="col-12 col-md-9">
<p class="float-right hidden-md-up">
<button type="button" class="btn btn-primary btn-sm" data-toggle="offcanvas">Toggle nav</button>
</p>
<div class="jumbotron">
<h1 class="text-center">
<?php
if (isset($_SESSION['username'])) {
echo $_SESSION['firstname'] . " " . $_SESSION['lastname'] . "'s";
} else {
echo "You are not logged in";
}
?>
</h1>
<h2 class="text-center">Vault</h2> </div>
<?php
if (isset($_SESSION['username'])) {
echo "
<form action='".setVaultPosts($conn)."' method='POST'>
<input type='hidden' name='uid' value='".$_SESSION['username']."'>
<input type='hidden' name='date' value='".date(' Y-m-d ')."'>
<textarea class='ckeditor' name='content'></textarea>
<br>
<button class='btn btn-default btn-lg' type='submit' name='vault_sub'>Submit</button>
";
getVaultPosts($conn);
} else {
echo "log in";
}
?>
</div>
<div class="col-6 col-md-3 sidebar-offcanvas" id="sidebar">
<div class="fixed">
<div class="list-group"> <a href="#" class="list-group-item active">Vault</a> <a href="recipient.php" class="list-group-item">Recipient Settings</a> <a href="settings.php" class="list-group-item">Account Settings</a> <a href="includes/logout.inc.php" class="list-group-item">Log Out</a> </div>
</div>
</div>
</div>
</div>
<?php include('footer.php'); ?>
你在哪里调用这个函数'setVaultPosts' –
你能告诉那里的header.php叫? – Hmmm
我打算在具有想要使用此功能的表单在本地服务器上运行的PHP页面调用它。 – cosmichero2025