PHP问题请高手帮忙
来源:百度知道 编辑:UC知道 时间:2024/05/29 21:28:59
出现下面问题是什么原因,请高手帮忙:
Warning: Cannot modify header information - headers already sent by (output started at /home/content/w/i/n/winindustry/html/main.php:54) in /home/content/w/i/n/winindustry/html/main.php on line 136
原代码如下:
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
Warning: Cannot modify header information - headers already sent by (output started at /home/content/w/i/n/winindustry/html/main.php:54) in /home/content/w/i/n/winindustry/html/main.php on line 136
原代码如下:
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
你在54行调用了session_start,但是你在136行又调用了header,调用header要求在其前面的代码中没有输出,调用session_start以后不能调用header了,要是需要跳转的话可以尝试一下用js解决。
因为上现的session_start()相对于下面的header来讲就是输出了,而header之前是不能有输出的,所以要用到输出缓存或者说以用Javascript来代替header
<?php ob_start(); ?>
if (!isset($_SESSION)) {
session_start();
} ... PHP codes ...
header ("Location: ....");
ob_end_flush();
?>
祝你早日解决问题.
Warning: Cannot modify header information - headers already sent by (output started at /home/content/w/i/n/winindustry/html/main.php:54) in /home/content/w/i/n/winindustry/html/main.php on line 136
session_start();header();等函数之前不能有任何的输出性的东西。包括空格。
可以在php.ini里面把output_buffering 改成 On
就可以了。
或者用ob类函数。
没事。不是什么大错误。。