已发送标头,无法找到空格或html输出

时间:2014-07-20 19:31:14

标签: php

收到此错误...通常在发送php / headers之前将其与空格/输出关联,但无法到达此底部。

所以错误是:

Warning: Cannot modify header information - headers already sent by 
(output started at
/Applications/MAMP/htdocs/website/index.php:11) in 
/Applications/MAMP/htdocs/website/process/checkautologin.php on line 65

Warning: Cannot modify header information - headers already sent by 
(output started at /Applications/MAMP/htdocs/website/index.php:11) 
in /Applications/MAMP/htdocs/website/process/checkautologin.php on line 120

索引PHP在顶部看起来像这样:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>BuildSanctuary</title>
    <?php
    require 'init.php';
    ?>

第11行是开放的php标记。

支票自动登录中的第65行是:

setcookie ("cookie",0,time() -3600,'/');

其周围的代码是:

// 'login' the user by setting the usual sessions
$_SESSION['user'] = $usernameuser;
$_SESSION['userid'] = $userid;
$_SESSION['logged'] = "1";
setcookie("cookie",0,time() -3600,'/');

// query the database to try and find a mactching row:
$query = " DELETE FROM `remember_me` WHERE `token` = :token "; 

// Create bound values
$query_params = array( 
  ':token' => $row['token'],
); 

这是底部:

// set new cookie
setcookie ("cookie",$new_cookie_val,time() + (10 * 365 * 24 * 60 * 60),'/');
} 
catch(PDOException $ex) 
{   <-- this is line 120.           
}

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

不正确:

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>BuildSanctuary</title>
    <?php
    require 'init.php';
    ?>

正确:

<?php
require 'init.php';
?>
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>BuildSanctuary</title>