警告:不能修改标题信息 - 已经发送的标题 [英] Warning: Cannot modify header information - headers already sent by

查看:91
本文介绍了警告:不能修改标题信息 - 已经发送的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 警告:不能修改标题信息 - 已经由(输出在
/ www / 110mb中以/www/110mb.com/m/u/s/i/c/k/i/n/musicking/htdocs/player.php:8)开始
。 com / m / u / s / i / c / k / i / n / musicking / htdocs / player.php on line 24

您可以请求帮助吗?

 <!DOCTYPE html PUBLIC -  // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> 
< html xmlns =http://www.w3.org/1999/xhtml>
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = utf-8/>
< title>播放器< / title>
< / head>
< body>
<?php
if(isset($ _ POST [song])&& $ _POST ['song']!=)
{
$歌曲= $ _POST [歌曲];

else {$ song = array();}
for($ i =0; $ i }
//开始新的php codep
//创建doctype
// $ array = array(
//'song.mp3','song.mp3','song .mp3',
//);
$ dom = new DOMDocument(1.0);
//以纯文本的形式在浏览器中显示文档
//为了便于阅读目的
header(Content-Type:text / plain);
//创建根元素
$ root = $ dom-> createElement(xml);
$ dom-> appendChild($ root);
$ i =1;
foreach($ song as $ counter){
//创建子元素
$ song = $ dom-> createElement(track);
$ root-> appendChild($ song);
$ song1 = $ dom-> createElement(path);
$ song-> appendChild($ song1);
//创建文本节点
$ text = $ dom-> createTextNode($ counter);
$ song1-> appendChild($ text);
$ song1 = $ dom-> createElement(title);
$ song-> appendChild($ song1);
$ text = $ dom-> createTextNode(song。$ i);
$ song1-> appendChild($ text);
$ i ++;

//保存并显示树
$ dom-> save(playlist.xml);
?>
< script type =text / javascriptsrc =swfobject.js>
< / script>
< div id =flashPlayer>
此文本将被Flash音乐播放器替换。
< / div>
< script type =text / javascript>
var so = new SWFObject(playerMultipleList.swf,mymovie,295,200,7,#FFFFFF);
so.addVariable(autoPlay,yes)
so.addVariable(playlistPath,playlist.xml)
so.write(flashPlayer);
< / script>
< / body>
< / html>


解决方案

错误信息由于出现的HTML而触发在您的第一个<?php 标记之前。在调用 header()之前,您不能输出任何内容。要解决此错误,请使用<?php 标记启动您的文档,并且在完成处理为Flash输出XML的条件后才开始输出HTML。



更简洁的解决方案是将Flash的XML生成和HTML输出分离到不同的文件中。


When I run player.php it's giving this error:

Warning: Cannot modify header information - headers already sent by (output started 
at /www/110mb.com/m/u/s/i/c/k/i/n/musicking/htdocs/player.php:8) in
/www/110mb.com/m/u/s/i/c/k/i/n/musicking/htdocs/player.php on line 24

Can you please help?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Player</title>
</head>
<body>
<?php
if(isset($_POST["song"])&& $_POST['song'] != "")
    {
        $song = $_POST["song"];
    }
    else {$song=array();}
for ($i="0"; $i<count($song); $i++) {
}
//start of new php codep
// create doctype
//$array = array(
  //  'song.mp3','song.mp3','song.mp3',
//);
$dom = new DOMDocument("1.0");
// display document in browser as plain text
// for readability purposes
header("Content-Type: text/plain");
// create root element
$root = $dom->createElement("xml");
$dom->appendChild($root);
$i = "1";
foreach ($song as $counter) {
// create child element
$song = $dom->createElement("track");
$root->appendChild($song);
$song1 = $dom->createElement("path");
$song->appendChild($song1);
// create text node
$text = $dom->createTextNode($counter);
$song1->appendChild($text);
$song1 = $dom->createElement("title");
$song->appendChild($song1);
$text = $dom->createTextNode("song ".$i);
$song1->appendChild($text);
$i++;
}
// save and display tree
$dom->save("playlist.xml");
?>
<script type="text/javascript" src="swfobject.js">
</script>
<div id="flashPlayer">
  This text will be replaced by the flash music player.
</div>
<script type="text/javascript">
   var so = new SWFObject("playerMultipleList.swf", "mymovie", "295", "200", "7", "#FFFFFF");  
   so.addVariable("autoPlay","yes")
   so.addVariable("playlistPath","playlist.xml")
   so.write("flashPlayer");
</script>
</body>
</html>

解决方案

The error message is triggering because of the HTML that appears before your first <?php tag. You cannot output anything before header() is called. To fix this error start your document with the <?php tag and only start outputting HTML after you are done handling the condition that outputs XML for flash.

A cleaner solution would be to separate out the XML generation for flash and the HTML output into different files.

这篇关于警告:不能修改标题信息 - 已经发送的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆