<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-start]:无法发送会话缓存限制器 - 已在网站上发送的标题(在网站上开始输出)
警告:无法修改标题信息 - 已经由网站
中的(网站开始输出)发送的标题任何人都可以帮助我吗?
提前致谢....
答案 0 :(得分:5)
<?php
和?>
以外的任何内容构成内容(与echo
,print
等内容一样)将会话代码移至脚本顶部。
答案 1 :(得分:2)
所有使用session,cookies,header()等(修改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">
答案 2 :(得分:0)
警告:session_start()[function.session-start]:无法发送会话缓存限制器 - 已在网站中发送的标头(在网站上开始输出)
Warning: Cannot modify header information - headers already sent by (output started at website) in website
关于这两个问题:
---在代码顶部使用会话启动。在此之前,您可以使用ob_start()来清除输出缓冲区。
像,
<?php
ob_start();
session_start();
?>
答案 3 :(得分:0)
作为一般规则,在开始输出内容之前首先执行所有业务逻辑(例如会话管理)。
正如已经指出的那样,开始打印页面内容会自动发送标题。
答案 4 :(得分: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
?>