2012-06-18 24 views
11

orada aşağıdaki eşdeğer midir:Başlığa alternatif ("İçerik türü: text/xml");

header("Content-type: text/xml"); 

Ben Wordpress ile Google Maps kullanıyorum ve hata "başlıklar zaten gönderildi" olsun. Tüm dosyaları gözden geçirdim ve tüm boşlukları çıkardım ama hata hala görünüyor, sadece yukarıdaki kodu yapmanın başka bir yolu olup olmadığını merak ediyorum.

Bu

hatadır:

Warning: Cannot modify header information - headers already sent by (output started at /home/medicom/public_html/mapping/wp-content/themes/default/header.php:11) in /home/medicom/public_html/mapping/wp-content/themes/default/new-version1.php on line 45 

Ve bu benim sayfası - gönderildikleri sonra başlıklarını gönderemezsiniz http://www.mediwales.com/mapping/test/

<?php 
/** 
* @package WordPress 
* @subpackage Default_Theme 
* Template Name: Latest Version 
*/ 
?> 
<!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 profile="http://gmpg.org/xfn/11"> 
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type');?>; charset=<?php bloginfo('charset');?>" /> 
<title><?php wp_title('&laquo;', true, 'right');?></title> 
<link rel="stylesheet" href="<?php bloginfo('stylesheet_url');?>" type="text/css" media="screen" /> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script> 
<script src="<?php bloginfo('template_directory'); ?>/markerclusterer.js" type="text/javascript"></script> 
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" /> 
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAdnbfsmnsdaFBmEZfsJEmiWC7p0LLmMBSsffI9l26I_viUYjW7vRG7TlO-sRQKR0B_YAsP2VnDdVgsr4Aegvksdw" type="text/javascript"></script> 
<?php if (is_singular()) wp_enqueue_script('comment-reply'); ?> 
<?php wp_head(); ?> 
</head> 
<body <?php body_class(); ?> onload="load()" onunload="GUnload()"> 
    <?php if (have_posts()) : ?> 
     <?php while (have_posts()) : the_post(); ?> 
    <div id="body"> 
<?php 
require("database.php"); 
function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 
// Opens a connection to a MySQL server 
$connection=mysql_connect (localhost, $username, $password); 
if (!$connection) { 
    die('Not connected : ' . mysql_error()); 
} 
// Set the active MySQL database 
$db_selected = mysql_select_db($database, $connection); 
if (!$db_selected) { 
    die ('Can\'t use db : ' . mysql_error()); 
} 
// Select all the rows in the markers table 
$query = "SELECT * FROM markers WHERE 1"; 
$result = mysql_query($query); 
if (!$result) { 
    die('Invalid query: ' . mysql_error()); 
} 
header("Content-type: text/xml"); 
// Start XML file, echo parent node 
echo '<markers>'; 
// Iterate through the rows, printing XML nodes for each 
while ($row = @mysql_fetch_assoc($result)){ 
    // ADD TO XML DOCUMENT NODE 
    echo '<marker '; 
    echo 'name="' . parseToXML($row['name']) . '" '; 
    echo 'address="' . parseToXML($row['address']) . '" '; 
    echo 'lat="' . $row['lat'] . '" '; 
    echo 'lng="' . $row['lng'] . '" '; 
    echo 'type="' . $row['type'] . '" '; 
    echo '/>'; 
} 
// End XML file 
echo '</markers>'; 
?> 
<script type="text/javascript"> 
    //<![CDATA[ 
    var iconBlue = new GIcon(); 
    iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png'; 
    iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; 
    iconBlue.iconSize = new GSize(12, 20); 
    iconBlue.shadowSize = new GSize(22, 20); 
    iconBlue.iconAnchor = new GPoint(6, 20); 
    iconBlue.infoWindowAnchor = new GPoint(5, 1); 
    var iconRed = new GIcon(); 
    iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png'; 
    iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'; 
    iconRed.iconSize = new GSize(12, 20); 
    iconRed.shadowSize = new GSize(22, 20); 
    iconRed.iconAnchor = new GPoint(6, 20); 
    iconRed.infoWindowAnchor = new GPoint(5, 1); 
    var customIcons = []; 
    customIcons["restaurant"] = iconBlue; 
    customIcons["bar"] = iconRed; 
    function load() { 
     if (GBrowserIsCompatible()) { 
     var map = new GMap2(document.getElementById("map")); 
     map.addControl(new GSmallMapControl()); 
     map.addControl(new GMapTypeControl()); 
     map.setCenter(new GLatLng(47.614495, -122.341861), 13); 
     GDownloadUrl("phpsqlajax_genxml.php", function(data) { 
      var xml = GXml.parse(data); 
      var markers = xml.documentElement.getElementsByTagName("marker"); 
      for (var i = 0; i < markers.length; i++) { 
      var name = markers[i].getAttribute("name"); 
      var address = markers[i].getAttribute("address"); 
      var type = markers[i].getAttribute("type"); 
      var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), 
            parseFloat(markers[i].getAttribute("lng"))); 
      var marker = createMarker(point, name, address, type); 
      map.addOverlay(marker); 
      } 
     }); 
     } 
    } 
    function createMarker(point, name, address, type) { 
     var marker = new GMarker(point, customIcons[type]); 
     var html = "<b>" + name + "</b> <br/>" + address; 
     GEvent.addListener(marker, 'click', function() { 
     marker.openInfoWindowHtml(html); 
     }); 
     return marker; 
    } 
    //]]> 
    </script> 
    <div id="map" style="width: 500px; height: 300px"></div> 
</div> 
     <?php endwhile; ?> 
    <?php endif; ?> 
</div> 
<?php wp_footer(); ?> 
</body></html> 
+1

Eşdeğer yoktur. Düzeltme, gönderilecek başlıkların zorlandığı içeriğin nerede olduğunu bulmaktır. Byte Order Markasını duydun mu? Bu senin problemin olabilir. Ayrıca, header() 'i çağırmadan önce Wordpress'in içerik göndermesi gibi açık bir şey de olabilir. –

+2

"Satırlar zaten gönderildi" hatası hangi satırı gösteriyor? Tam bir dosya adı ve satır numarası almalısınız –

+0

@Pekka Bu sorunu daha önce çözmeye çalıştım ve pes ettim! Sorunumu zaten daha fazla bilgi ile güncellendi. – Rob

cevap

9

'da kanca kullanmayı deneyin Şimdi ne yaptığınızı görüyorum. Çıkışı ekrana gönderemezsiniz, ardından başlıkları değiştiremezsiniz. Harita işaretleyici bir XML dosyası oluşturmaya ve görüntülemek için indirmeye çalışıyorsanız, bunlar ayrı dosyalarda olmalıdır.

bu

<?php 
require("database.php"); 
function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','&lt;',$htmlStr); 
$xmlStr=str_replace('>','&gt;',$xmlStr); 
$xmlStr=str_replace('"','&quot;',$xmlStr); 
$xmlStr=str_replace("'",'&#39;',$xmlStr); 
$xmlStr=str_replace("&",'&amp;',$xmlStr); 
return $xmlStr; 
} 
// Opens a connection to a MySQL server 
$connection=mysql_connect (localhost, $username, $password); 
if (!$connection) { 
    die('Not connected : ' . mysql_error()); 
} 
// Set the active MySQL database 
$db_selected = mysql_select_db($database, $connection); 
if (!$db_selected) { 
    die ('Can\'t use db : ' . mysql_error()); 
} 
// Select all the rows in the markers table 
$query = "SELECT * FROM markers WHERE 1"; 
$result = mysql_query($query); 
if (!$result) { 
    die('Invalid query: ' . mysql_error()); 
} 
header("Content-type: text/xml"); 
// Start XML file, echo parent node 
echo '<markers>'; 
// Iterate through the rows, printing XML nodes for each 
while ($row = @mysql_fetch_assoc($result)){ 
    // ADD TO XML DOCUMENT NODE 
    echo '<marker '; 
    echo 'name="' . parseToXML($row['name']) . '" '; 
    echo 'address="' . parseToXML($row['address']) . '" '; 
    echo 'lat="' . $row['lat'] . '" '; 
    echo 'lng="' . $row['lng'] . '" '; 
    echo 'type="' . $row['type'] . '" '; 
    echo '/>'; 
} 
// End XML file 
echo '</markers>'; 
?> 

alın ve böylece javascript XML dosyasını indirebilirsiniz phpsqlajax_genxml.php yerleştirin. Aynı dosyada çok fazla şey yapmaya çalışıyorsunuz.

+0

Parlak, çok teşekkürler! – Rob

+0

@ Teamworksdesign.com Sorun değil – Nick

2

sayılı. WordPress

+0

Bunu yapmak için kancaları nasıl kullanırdım? Ayrıca sorumu daha fazla bilgi ile güncelledim. – Rob

İlgili konular