2010-06-24 47 views
-1
<div id="left-body-part-innerpage"> 
    <h1 class="mainheading">Contact Us</h1> 
    <div id="contactus-right-div" class="content"> 
    <?php session_start(); 
     if(isset($_POST['button2']))   
     { 
      if($_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'])) 
      { 
       $name = $_POST['name']; 
       // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
       session_destroy(); 
       header("Location: contactdb.php"); 
?> 

送我得到頭警告:在session_start()[function.session啓動]:無法發送會話緩存限制器 - 在網站不能更改頭信息 - 已經

已經發送了頭(輸出開始網站)

警告:不能修改標題信息 - 網站已發送的標題(輸出在網站開始)在網站

任何人都可以幫助我嗎?

在此先感謝....

+0

想想包括他的文件,而不是重定向到它。 – Svisstack 2010-06-24 10:39:34

+0

會話警告呢? – Rachel 2010-06-24 11:00:09

+0

只需在任何HTML之前放置標題功能即可。 – 2010-06-24 11:16:00

回答

0

一般來說,做所有的業務邏輯第一(如會話管理)開始的內容輸出之前。

正如已經指出的那樣,開始打印頁面內容將自動發送頁眉。

5
  1. 啓動會話需要設置HTTP頭
  2. 您不能發送頭可以發送的內容
  3. 後任何外界<?php?>構成內容(如做什麼你echo,print,等)

移動你的會議代碼到腳本的頂部。

+0

嗨大衛, 我已經移動session_start()在我的頁面開始,但我仍然收到相同的警告。 – Rachel 2010-06-24 10:49:03

+0

@Rachel你是否已將整個代碼塊移到頁面的開頭? – 2010-06-24 10:49:34

+0

相信與否,'header'函數也會發送內容後不能出現的標題。 – Quentin 2010-06-24 10:53:30

2

與會話,餅乾,頭(所有的工作)等(一切修改HTTP頭)必須在腳本的第一輸出前完成......把你的PHP代碼塊的標記

<?php session_start(); 
    if(isset($_POST['button2']))   
    { 
     if($_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'])) 
     { 
      $name = $_POST['name']; 
      // Insert you code for processing the form here, e.g emailing the submission, entering it into a database. 
      session_destroy(); 
      header("Location: contactdb.php");?> 

<div id="left-body-part-innerpage"> 
<h1 class="mainheading">Contact Us</h1> 
<div id="contactus-right-div" class="content"> 
0

警告之前:在session_start()[function.session啓動]:無法發送會話緩存限制器 - 在網站

Warning: Cannot modify header information - headers already sent by (output started at website) in website 

已經發送了頭(輸出開始網站)關於此兩期:

---在你的代碼中使用會話開始。在此之前,您可以使用ob_start()來清除輸出緩衝區。

一樣,

<?php 
ob_start(); 
session_start(); 
?> 
0

在發送標題之前使用輸出緩衝來防止輸出。

<?php 

function callback($buffer) { 

    // заменить все apples на oranges 
    return (ereg_replace("apples", "oranges", $buffer)); 

} 

ob_start("callback"); 
//HERE you can send any headers you want. callback is not required here if you don't want 
?> 

<html> 
<body> 
<p>It's like comparing apples to oranges. 
</body> 
</html> 

<?php 
//And here you can 
ob_end_flush(); 
//If send headers here - you'll get warning 
?> 
相關問題