mediaguy2004 Posted January 23, 2007 Share Posted January 23, 2007 Hello guys I am working on the rss tutorial. I did get it to work but I am having a problem.I am getting this errorWarning: Cannot add header information - headers already sent by (output started at /var/www/html/news_rss/Test2.php:8) in /www/news_rss/Test2.php on line 56. Can any one tell me what this means.Below is the codeThanks for your help..<?phpinclude "config.php";$link = mysql_connect($config['db_host'],$config['db_user'],$config['db_pass']) or die();mysql_select_db($config['db_name']) or die();$news_headlines = mysql_query("SELECT n.*,a.* FROM news AS n LEFT JOIN authors AS a ON a.aid=n.n_author_id ORDER BY n.n_time DESC".(is_numeric($config['headlines']) && $config['headlines']>0 ? " LIMIT {$config['headlines']}" : null));$items_output = null;if(mysql_num_rows($news_headlines)){ while($headline = mysql_fetch_assoc($news_headlines)) { $link = htmlentities("http://example.com/index.php?act=news&id={$headline['nid']}"); $pubdate = gmdate('r',$headline['n_time']); $author = $config['show_author_info'] ? "nttt<author>{$headline['a_email']} ({$headline['a_name']})</author>" : null; $description = nl2br($headline['n_body']); $items_output .= <<<EOF <item> <title>{$headline['n_title']}</title> <description> {$description} </description> <link>{$link}</link> <pubDate>{$pubdate}</pubDate>{$author} </item>EOF; }}$config['encoding'] = empty($config['encoding']) ? 'ISO-8859-1' : $config['encoding'];$copyright = empty($config['copyright']) ? null : "ntt<copyright>".str_replace('{year}',date('Y'),$config['copyright'])."</copyright>";$pubdate = $config['show_feed_pubdate'] ? "ntt<pubDate>".gmdate('r')."</pubDate>" : null;$language = empty($config['language']) ? null : "ntt<language>{$config['language']}</language>";$output = <<<EOF<?xml version="1.0" encoding="{$config['encoding']}" ?><rss version="2.0"> <channel> <title>{$config['feed_title']}</title> <link>{$config['link']}</link> <description>{$config['description']}</description>{$copyright}{$pubdate}{$language}{$items_output} </channel></rss>EOF;header("Content-type: application/xml; charset={$config['encoding']}");echo $output;?> Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/ Share on other sites More sharing options...
Jessica Posted January 23, 2007 Share Posted January 23, 2007 You should read the topic on header errors. You can't output before setting the header. Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/#findComment-167492 Share on other sites More sharing options...
mediaguy2004 Posted January 23, 2007 Author Share Posted January 23, 2007 Do you have a link to it I will try to seach for it.. Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/#findComment-167509 Share on other sites More sharing options...
simcoweb Posted January 23, 2007 Share Posted January 23, 2007 http://www.phpfreaks.com/forums/index.php/topic,37442.0.html Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/#findComment-167516 Share on other sites More sharing options...
mediaguy2004 Posted January 23, 2007 Author Share Posted January 23, 2007 Thanks Guys My seaches where turnig up everything on errors. Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/#findComment-167525 Share on other sites More sharing options...
mediaguy2004 Posted January 25, 2007 Author Share Posted January 25, 2007 OK How do you do that Iam stiil a newbie on php.. Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/#findComment-168684 Share on other sites More sharing options...
corbin Posted January 25, 2007 Share Posted January 25, 2007 You must send header("Content-type: application/xml; charset={$config['encoding']}"); to the browser before ANYTHING else even if it's just whitespace (you can have whitespace in your php scripts; it just cannot be outputted to the browser.)Try moving that line to the top of the file. Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/#findComment-168687 Share on other sites More sharing options...
mediaguy2004 Posted January 25, 2007 Author Share Posted January 25, 2007 OK I tried it, It will give me the page with out the xml page jus a plain html page with the error. Plus I tried a couple of things. when I leave it alone I can see all the info from the headlines table and not author tablewhen I make this change - I removed the header Info form the config file. That gaves me the xml page Then I get this errorThe XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error Then this error tooOnly one top level element is allowed in an XML document. Error processing resource 'http://localhost/test_rss/rss.php'. Line 8, Position 2 <b>Warning</b>: Cannot add header information - headers already sent by (output started at /www/test_rss/rss.php:5) in <b>www/test_rss/rss.php</b> on line <b>53</b><br /> anyone has any ideasThanks Quote Link to comment https://forums.phpfreaks.com/topic/35409-rss-tutorial/#findComment-168737 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.