Autor Zpráva
deliQus
Profil
Mám tento php skript na generovaní rss kanálu:

<?php
  require_once("config.php");
  header('Expires: ' . gmdate('D, d M Y H:i:s') . '  GMT');
  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . '  GMT');
  header('Content-Type: text/xml; charset=utf-8');
?>
<xml version="1.0" encoding="utf-8">
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>web.com</title>
    <link>http://www.web.com/</link>
    <webMaster>ms@web.com (MS)</webMaster>
    <category>finance, spoření, spořící účty, termínované účty, stavební spoření, penziní připojištění</category>
    <docs>http://backend.userland.com/rss</docs>
    <lastBuildDate><?php echo gmdate("D, d M Y H:i:s")." GMT"; ?></lastBuildDate>
    <atom:link href="http://www.web.com/rss/" rel="self" type="application/rss+xml" />
    <image>
      <url>http://www.web.com/graphics/mini_title.gif</url>
      <title>web.com</title>
      <link>http://www.web.com/</link>
    </image>
<?php
    $res = mysql_query("SELECT * FROM `clanky` order by datum",$GLOBALS["link"]);
    while($rec = mysql_fetch_array($res)) {
	
	?>
    <item>
      <title>Článek</title>
      <link>http://www.web.com/clanky&amp;id=<?php echo $rec["id"]; ?>/</link>
      <guid>http://www.web.com/clanky&amp;id<?php echo $rec["id"]; ?>/</guid>
      <description><?php echo htmlspecialchars(strip_tags($rec["nadpis"])); ?></description>
      <pubDate><?php echo $rec["datum"]; ?></pubDate>
    </item>
<?php
    }
?>


A hází mi to: Warning: Cannot modify header information - headers already sent by (output started at /var/www/web5/osporeni.com/osporeni.com/index.php:2) in /var/www/web5/osporeni.com/osporeni.com/rss.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web5/osporeni.com/osporeni.com/index.php:2) in /var/www/web5/osporeni.com/osporeni.com/rss.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web5/osporeni.com/osporeni.com/index.php:2) in /var/www/web5/osporeni.com/osporeni.com/rss.php on line 5
Nevíte čím by to mohlo být ? Respektive, jak to udělat správně.
Alphard
Profil
Jestli máte zapnuté short_open_tags, tak je problém v <?xml. Řešení najdete v FAQ.
GeneralDv
Profil
<?xml version="1.0" encoding="utf-8"?>

Tagy pro PHP, viz http://diskuse.jakpsatweb.cz/?action=vthread&forum=9&topic=2111

//pozdě!
fuckin
Profil
Musíš si uvědomit že <?xml version="1.0" encoding="utf-8"?> tímto zapneš php jednoduše řečeno. Dále jsi tam měl další chybu, mas to tam zakomentované.

<?php
  require_once("config.php");
  header('Expires: ' . gmdate('D, d M Y H:i:s') . '  GMT');
  header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . '  GMT');
  header('Content-Type: text/xml; charset=utf-8');

echo '<?xml version="1.0" encoding="utf-8"?>'; ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>web.com</title>
    <link>http://www.web.com/</link>
    <webMaster>ms@web.com (MS)</webMaster>
    <category>finance, spoření, spořící účty, termínované účty, stavební spoření, penziní připojištění</category>
    <docs>http://backend.userland.com/rss</docs>
    <lastBuildDate><?php echo gmdate("D, d M Y H:i:s")." GMT"; ?></lastBuildDate>
    <atom:link href="http://www.web.com/rss/" rel="self" type="application/rss+xml" />
    <image>
      <url>http://www.web.com/graphics/mini_title.gif</url>
      <title>web.com</title>
      <link>http://www.web.com/</link>
    </image>
<?php
    $sql = "SELECT * FROM `clanky` WHERE id='".$_GET['id']."'LIMIT 1"; //odebrano  ,$GLOBALS["link"]; nechapu co to ma byt
    $res = mysql_query($sql);
    while($rec = mysql_fetch_array($res)) {
    
    ?>
    <item>
      <title>Článek</title>
      <link>http://www.web.com/clanky&amp;id=<?php echo $rec["id"]; ?>/</link>
      <guid>http://www.web.com/clanky&amp;id<?php echo $rec["id"]; ?>/</guid>
      <description><?php echo htmlspecialchars(strip_tags($rec["nadpis"])); ?>/description>
      <pubDate><?php echo $rec["datum"]; ?></pubDate>
    </item>
<?php
    }
?>
deliQus
Profil
GeneralDv:
Jojo, to už jsem opravil :-)
deliQus
Profil
Stále to hází:

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web5/web.com/web.com/index.php:2) in /var/www/web5/web.com/web.com/rss.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web5/web.com/web.com/index.php:2) in /var/www/web5/web.com/web.com/rss.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at /var/www/web5/web.com/web.com/index.php:2) in /var/www/web5/web.com/web.com/rss.php on line 5
fuckin
Profil
Citováno z FAQ na tomto serveru, stačí jen hledat :)

headers already sent...
Pokud už byl generovaný nějaký výstup, tak už nelze používat funkce header(), setcookie() ani session_start(). Jejich volání skončí chybou.
Přesvědčete se, že před začátkem <?php ?> není žádný text (ani mezera) a že nebylo nic odesláno třeba funkcemi jako echo nebo print.
Pokud je text v UTF-8, tím výstupem může být i tzv. BOM signatura, vizte výše zmíněný Divný znak (čtvereček)....
deliQus
Profil
Teď mi to funguje jen když to zobrazím v indexu ( index.php?page=rss ) ale když dam normal web.com/rss.php tak to nejde a hází to:

Warning: mysql_query() [function.mysql-query]: Access denied for user 'web_com'@'localhost' (using password: NO) in /var/www/web5/web.com/web.com/rss.php on line 20

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/web5/web.com/web.com/rss.php on line 20

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/web5/web.com/web.com/rss.php on line 21
Alphard
Profil
Chyba s připojením, k databázi se připojujete v config.php?
deliQus
Profil
Jojo, přes config.php
fuckin
Profil
Protože v indexu je evidentně navázáno připojení k databázi. Kdežto v rss.php nikoli. Z chybových hlášek lze vidět že nejste připojený k databázi.
Warning: mysql_query() [function.mysql-query]: Access denied for user 'web_com'@'localhost' (using password: NO) in /var/www/web5/web.com/web.com/rss.php on line 20 

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /var/www/web5/web.com/web.com/rss.php on line 20 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/web5/web.com/web.com/rss.php on line 21


Nevymazals ten config.php z toho důvodu aby se tam neukazovalo to headers already sent ?
deliQus
Profil
Jojo, měl jsem tam chybu, už to jde, díky

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm:

0