我已經看了很多修復這個我試過刪除空白,但沒有,我試過使用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