首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >上面写着“头已经发了”,但还没有

上面写着“头已经发了”,但还没有
EN

Stack Overflow用户
提问于 2015-08-03 16:38:27
回答 1查看 49关注 0票数 1

我很困惑,最近我刚刚从本地服务器(Wamp)切换到一个实时服务器(DreamHost -共享)。

现在,我的本地服务器工作得很好,但是在活动服务器上它正在引发Cannot modify header information。这很奇怪,因为那里什么都没发生!我遗漏了什么吗?

代码语言:javascript
复制
<!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文件:

代码语言:javascript
复制
<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.,我不想压制错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-03 16:40:43

您的session_start()命令应该始终位于每个文件的top处。另外,如果您的代码中有任何header函数,那么任何和所有回显命令都应该在它之后而不是在它之前。

因此,例如:

代码语言:javascript
复制
<?php
if(1==1)
{
header('Locatio:something.php');//should be immediately after the `if` start braces.
echo "something here";
}
?>

现在,一些不对劲的事情:-

代码语言:javascript
复制
<?php
if(1==1)
{
echo "something here";
header('Locatio:something.php');//should be immediately after the `if` start braces.
}
?>

现在,上面的代码^^将通过headers already sent error

?>

代码语言:javascript
复制
<?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");

?>

?>
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31792502

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档