wwfc_barmy_army Posted April 3, 2008 Share Posted April 3, 2008 Hello. I'm trying to use include to show a XML file (with a XSL stylesheet on) although i get this error: Warning: Cannot modify header information - headers already sent by (output started at C:\public_html\hotelbookings\index.php: in C:\public_html\hotelbookings\fulllistxml.php on line 2 The first two lines of the phpfile that generates the XML is : <?php header("Content-type: text/xml"); Any ideas how i can get around this? Thanks. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 What is the code for fulllistxml.php and index.php Also, is the URL pointing to fulllistxml or is it in an include()? Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted April 3, 2008 Author Share Posted April 3, 2008 fulllistxml.php: <?php header("Content-type: text/xml"); $host = "localhost"; $user = "root"; $pass = "****"; $database = "***"; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $query = "SELECT * FROM ****"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output = "<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>\n"; $xml_output .= "<hotellist>\n"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t<hotel>\n"; ...etc.... index.php beginning code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Hotel Booking System</title> <meta name="keywords" content="" /> <meta name="description" content="" /> <link href="default.css" rel="stylesheet" type="text/css" /> <script src="livesearch.js"></script> <?php include("dbconnect.php"); ?> </head> <body> <div id="header"> It is included like: <?php include("fulllistxml.php"); ?> Thanks. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 What page includes fulllistxml.php? Basically, if you want the XML to show as an XML file, you can only send the header() and the XML to the screen. At some point, index.php is running, and since it sends output to the screen it will cause it to fail. fulllistxml.php needs to be opened in the browser independent of everything else. Like: <a href="filllistxml.php">View XML</a> Make sense? Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted April 3, 2008 Author Share Posted April 3, 2008 Ah, so it can't be included into the index.php page in any way? Thanks. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 you have a couple of options if you want it displayed in-page: -Use my recommendation from earlier, but load it in an iframe instead of a new window -Print it out the way you have it, but don't send headers, and run the XML through htmlspecialchars() first, so it translates the < and > to < and $gt; ...there might be more, but those are the first that come to my head Quote Link to comment Share on other sites More sharing options...
lordfrikk Posted April 3, 2008 Share Posted April 3, 2008 You can also use Output Buffering (see php.net). Quote Link to comment Share on other sites More sharing options...
rhodesa Posted April 3, 2008 Share Posted April 3, 2008 There is no need to output buffer because he is already storing the XML in a string. But, if you try to do a print $xml_string the browser will see it as HTML (since the content type on the page is text/html). Running it through htmlspecialchars() though will make it print the tags. Quote Link to comment 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.