我很困惑,我最近刚刚从本地服务器(Wamp)切换到实时服务器(DreamHost - Shared)。
现在,我的本地服务器工作正常,但在实时服务器上它正在提升Cannot modify header information
。这很奇怪,因为那里什么也没发生!我有什么遗失的东西吗?
<!DOCTYPE html>
<html>
<head>
<?php include("/home/postinowner/postin.me/includes/head.php");?>
<title> Your Words, Your Thoughts, So Get POSTIN'</title>
<link type="text/css" rel="stylesheet" href="css/style.home.php.css"/>
</head>
<body>
<div id="wrapper" class="container">
<?php
//Grabbing the database connection
require("/home/postinowner/postin.me/db_connection.php");
//Starts the session
session_start();
//Grabs the user class
require("/home/postinowner/postin.me/classes.php");
//Grabs all of the categories
require("/home/postinowner/postin.me/allcategories.php");
//Grabs the header
include("/home/postinowner/postin.me/includes/header.php");
?>
然后是head.php
文件:
<html lang="en-US">
<link rel="icon" type="image/png" href="http://localhost/postin'/images/favicon.ico?v=2">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php mb_internal_encoding("UTF-8"); ?>
<link type="text/css" rel="stylesheet" href="http://localhost/postin'/css/bootstrap.min.css">
<link type="text/css" rel="stylesheet" href="http://localhost/postin'/css/bootstrap-theme.min.css">
<link type="text/css" rel="stylesheet" href="http://localhost/postin'/css/style.css"/>
<link type="text/css" rel="stylesheet" href="http://localhost/postin'/css/style.adboxs.css"/>
<style type="text/css">
<!--
body {
margin: 0px;
}
-->
</style>
<style type="text/css">
a:hover {color: orange;} /* mouse over link */
a:active {color: orange;} /* selected link */
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
<script src="js/bootstrap.min.js"> </script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
P.S。,我不想压制错误。
答案 0 :(得分:4)
您的session_start()
命令应始终位于每个文件的top
。此外,如果您的代码中有任何header
函数,那么任何和所有echo命令都应该在它之后,而不是之前。
因此,例如: -
<?php
if(1==1)
{
header('Locatio:something.php');//should be immediately after the `if` start braces.
echo "something here";
}
?>
现在,出了点问题: -
<?php
if(1==1)
{
echo "something here";
header('Locatio:something.php');//should be immediately after the `if` start braces.
}
?>
现在上面的代码^^将通过headers already sent error
。
&GT;
<?php
session_start();
require("/home/postinowner/postin.me/db_connection.php");
?>
<!DOCTYPE html>
<html>
<head>
<?php include("/home/postinowner/postin.me/includes/head.php");?>
<title> Your Words, Your Thoughts, So Get POSTIN'</title>
<link type="text/css" rel="stylesheet" href="css/style.home.php.css"/>
</head>
<body>
<div id="wrapper" class="container">
<?php
//Grabs the user class
require("/home/postinowner/postin.me/classes.php");
//Grabs all of the categories
require("/home/postinowner/postin.me/allcategories.php");
//Grabs the header
include("/home/postinowner/postin.me/includes/header.php");
?>
?>