2010-06-24 85 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 
?> 
相关问题