Php 警告帮助:无法修改标题信息-标题已由发送(输出开始于C:\\\\\错误
db_connect文件:Php 警告帮助:无法修改标题信息-标题已由发送(输出开始于C:\\\\\错误,php,http,header,Php,Http,Header,db_connect文件: <?php //connects to the database $username = "username"; $password = "password"; $hostname = "host"; $database="database"; $link=mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL".m
<?php
//connects to the database
$username = "username";
$password = "password";
$hostname = "host";
$database="database";
$link=mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL".mysql_error());
mysql_select_db($database, $link) or die("Could not select the database".mysql_error());
?>
进程登录文件:
<?php session_start();
include "DB_connect.php";
if( !isset($_SESSION) )
$username=$_POST["UserName"];
$password=$_POST["Password"];
$errormessage = "";
$sql="SELECT * FROM members where UserName='$username' and Password='$password'";
$result = mysql_query($sql, $link) or exit('$sql failed: '.mysql_error());
$num_rows = mysql_num_rows($result);
if($num_rows==0){header("Location:login.php");}
else {
header("Location:MyPage.php");
exit;
}?>
在使用header()函数重新定义头之前,不能向HTTP正文发送任何字符,这意味着不开始响应的正文部分
检查任何包含的文件在开头或结尾没有任何空白字符行,并检查在调用header()之前是否没有回音
当在调用header()之前发送字符时,总是会发生此问题。在您发布的代码之前的某个地方,您要么发送了一个空行,要么更可能发送了一些实际内容。一旦PHP开始发送页面内容,您就不能再更新标题(因为它们在页面内容之前发送)
调用。在处理会话和登录等操作时,在打开之前,请确保文件顶部没有空格。您应该使用输出缓冲来防止标头错误。类似以下内容:
//Start the output buffer so we don't create any errors with headers
ob_start();
//Check to see if it has been started
if(session_started()){
echo 'The session has been started.<br />';
}else{
echo 'The session has not been started.<br />';
}
//Start the session
echo 'Starting Session...<br />';
session_start();
//启动输出缓冲区,这样我们就不会在标题中创建任何错误
ob_start();
//检查是否已启动
如果(会话_已启动()){
回显“会话已启动。
”;
}否则{
回显“会话尚未启动。
”;
}
//开始会话
回显“正在启动会话…
”;
会话_start();
//Start the output buffer so we don't create any errors with headers
ob_start();
//Check to see if it has been started
if(session_started()){
echo 'The session has been started.<br />';
}else{
echo 'The session has not been started.<br />';
}
//Start the session
echo 'Starting Session...<br />';
session_start();