Include with RSS

Hi,

I’m want to use an include for my variables.
The below code works because the include is commented out.
As soon as I take out the comment the rss doesn’t work anymore.
It doesn’t come from the content of the rss.inc, as I can copy paste the code just below the commented out include and that works.
the admin folder exists, as does the custom folder, and of course the rss.inc file

Can an included not be used with creating an RSS file ?

<?php
header(‘Content-Type: text/xml’);
echo ‘<’.‘?xml version=“1.0” encoding=“iso-8859-1”?’.‘>’;
echo “<rss version=\“2.0\”>”;
//include(‘admin/custom/rss.inc’);

TIA
PAtricia

As pointed out in posts #6 and #7 that’s not a very good idea. If you want to indicate in the filename that it is included in another file you could better use .inc.php than .inc
The reason is that if someone browses to an .inc file they will (depending on the web server config) just see the source code of that file…

OK, thanks for pointing that out, I will change it

Pat

I couldn’t recall offhand, but as you say, its something to do with the mixup of <? tags somewhere along the line…

I do realise that is a different subject entirely but having *.inc files which contain PHP code which are not automatically parsed by PHP is not generally a good idea, even if they are kept out of the main public document tree.

So if your server is not set to parse .inc files as PHP then it is seemingly treating it as plain text.

To eradicate the problem of us not being exactly sure of what the parser is making of short_tags being on or not, plus all that fiddling about with <?xml tags, why not try it this way:


<?php
// bring in your variables
include 'rss.inc' ;
// issue your header
header('Content-Type: text/xml');
?>
<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">

.. and so on, or drop back into PHP and output your channel
<?php
foreach( $items as $item ){
// output the item
}
?>

Does any of that help at all?

If not it seems you may have to rename rss.inc to rss.inc.php, otherwise this might turn out to be a short_tags = on issue, so you could possibly overrule that for just this page, though you would have to look that setting up in the manual and see if it can be changed on a per script basis.

[fphp]ini_set/fphp;

you are correct, the rss.php that is included didn’t start with a <?php
I thought that since it was included within php that the included file didn’t need it.
I just changed it and IT WORKS
Thanks

I’ve also been able to change the file name from rss.php to rss.inc, and that works good also.

Does rss.php start with a line that just says <?php ?
Looks like it doesn’t, but it should :slight_smile:

with the include commented out

<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
<channel>
<title>MCC_RSS</title>
<link>http://www.mysite.com/rss.php</link>
 <description>MCC</description>
<pubDate>sep, 12 2010 00:12:30 EST</pubDate>
<lastBuildDate>sep, 12 2010 00:12:30 EST</lastBuildDate>
<ttl> 120 </ttl>
<category> cyclotourisme, cyclosport, vtt</category>
<copyright> Copyright Cabinet Mazuel Riom France.</copyright>
<webMaster> claude@mysite.com</webMaster>
<managingEditor> claude@mysite.com</managingEditor> <language>fr</language>
<image>
<title>www.mysite.com</title>
<url>http://www.mysite.com/feed-icon-28x28.png</url>
<link>http://www.mysite.com</link>
<description>.Le se consacre &#224; la pratique du cyclotourisme, cyclosport, cyclisme, v&#233;lo, VTT, cyclisme f&#233;minin dans le Puy-de-D&#244;me Auvergne</description>
</image>
<item>
<title>Dimanche 3 Octobre 8h30 :</title>
<link>
<![CDATA[http://www.mysite.com/evenements.php?id_art=526]]>
</link>
<description>
</description>
<pubDate>28-09-2010</pubDate>
</item>

. . . .
</channel>
</rss>

with the include not commented out. (the only difference is that I take out the // before the include command. As you can see, the variables appear in the html code. These same variables are there in the above code also, yet they don’t appear in the HTML. Bascially I copied the affection of the variables from the include and pasted them directly in my PHP page.

<?xml version="1.0" encoding="iso-8859-1"?>
<rss version="2.0">
$rss_title="MCC_RSS";
$rss_site_url= "www.mysite.com";
$rss_description= "MCC";
$rss_pub_date= "sep, 12 2010 00:12:30 EST";
$rss_category= "cyclotourisme, cyclosport, vtt";
$rss_copywrite="Copyright Cabinet Mazuel Riom France.";
$rss_webmaster= "claude@mysite.com";
$rss_editor="claude@mysite.com" ;
$rss_site_description= "Le cyclo club se consacre &#195;  la pratique du cyclotourisme, cyclosport, cyclisme, v&#195;&#169;lo, VTT, cyclisme f&#195;&#169;minin dans le Puy-de-D&#195;&#180;me Auvergne" ;
$rss_typ_art= " and (typ_art= 'accueil' or typ_art= 'sorties')";
$rss_page="evenements.php";

	//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&<channel>
<title>MCC_RSS</title>
<link>http://www.mysite.com/rss.php</link> <description>Mozac Cyclo club</description>
<pubDate>sep, 12 2010 00:12:30 EST</pubDate>
<lastBuildDate>sep, 12 2010 00:12:30 EST</lastBuildDate>
<ttl> 120 </ttl>
<category> cyclotourisme, cyclosport, vtt</category>
<copyright> Copyright Cabinet Mazuel Riom France.</copyright>
<webMaster> claude@mysite.com</webMaster>
<managingEditor> claude@mysite.com</managingEditor> <language>fr</language>
<image>
<title>www.mysite.com</title>
<url>http://www.mysite.com/feed-icon-28x28.png</url>
<link>http://www.mysite.com</link>
<description>.Le cyclo club se consacre &#195;  la pratique du cyclotourisme, cyclosport, cyclisme, v&#195;&#169;lo, VTT, cyclisme f&#195;&#169;minin dans le Puy-de-D&#195;&#180;me Auvergne</description>
</image>
<item>
<title>Dimanche 3 Octobre 8h30 :</title>
<link>
<![CDATA[http://www.mozaccycloclub.com/evenements.php?id_art=526]]>
</link>
<description>
</description>
<pubDate>28-09-2010</pubDate>
</item>
&#8230;
</channel>
</rss>


Thanks for the help

still no go, but thanks for all the input.

If I put the include before the header, I get an error messages saying “xml poorly formed”

I renamed my included file to be rss.php instead of rss.inc.
Below is the code that does not work.
rss.php contains the same code as the commented out lines
If I take out the comments my rss is generated properly.
If I leave in the comments the generated code is strange.

Generated code

<?xml version="1.0" encoding="iso-8859-1"?><rss version="2.0">
$rss_title="MCC_RSS";
$rss_site_url= "www.mysite.com";
$rss_description= "MCC";
$rss_pub_date= "sep, 12 2010 00:12:30 EST";
$rss_last_build_date= "sep, 12 2010 00:12:30 EST";
$rss_category= "cyclotourisme, cyclosport, vtt";
$rss_copywrite="Copyright Cabinet France.";
$rss_webmaster= "claude@mysite.com";
$rss_editor="claude@mysite.com" ;
$rss_site_description= "Le club se consacre &#195;  la pratique du cyclotourisme, cyclosport, cyclisme, v&#195;&#169;lo, VTT, cyclisme f&#195;&#169;minin dans le Puy-de-D&#195;&#180;me Auvergne" ;
$rss_typ_art= " and (typ_art= 'accueil' or typ_art= 'sorties')";
$rss_page="evenements.php";
$rss_order_by="date_art desc";	

<channel><title></title><link>http:///rss.php</link> <description></description><pubDate></pubDate><lastBuildDate></lastBuildDate><ttl> 120 </ttl><category> </category>



Source Code

<?php
header('Content-Type: text/xml');

echo '<'.'?xml version="1.0" encoding="iso-8859-1"?'.'>';
echo "<rss version=\\"2.0\\">";

include('admin/custom/rss.php');

// varibles to be modified per site
	//$rss_title="MCC_RSS";
//	$rss_site_url= "www.mysite.com";
//	$rss_description= "MCC";
//	$rss_pub_date= "sep, 12 2010 00:12:30 EST";
//	$rss_last_build_date= "sep, 12 2010 00:12:30 EST";
//	$rss_category= "cyclotourisme, cyclosport, vtt";
//	$rss_webmaster= "claude@mysite.com";
//	$rss_editor="claude@mysite.com" ;
//	$rss_site_description= "Le club se consacre &#224; la pratique du cyclotourisme, cyclosport, cyclisme, v&#233;lo, VTT, cyclisme f&#233;minin dans le Puy-de-D&#244;me Auvergne" ;
//		// modifiy  the following to include the article wanted in the RSS, must exist in admin, custom,  pagenames.inc
//	$rss_typ_art= " and (typ_art= 'accueil' or typ_art= 'sorties')";
//		// the php is the page name to be used to display the articles
//	$rss_page="evenements.php";
//		// order to show the articles
//	$rss_order_by="date_art desc";	
// end of variables to be modified by site
$rss_query = "SELECT titre, id_art , typ_art, expire, date_art, message, docs, link FROM info  where date_art <= current_date and  expire > current_date " .$rss_typ_art .  " ORDER BY " .            $rss_order_by   ;		

$rss_link ="http://".$rss_site_url;
$rss_url_image = "http://".$rss_site_url."/feed-icon-28x28.png";
$rss_link_rss_php="http://".$rss_site_url."/rss.php";
$my_link_page= "http://".$rss_site_url . "/" . $rss_page . ".php?id_art=" ;
$rss_copywrite="Copyright Cabinet France.";

echo "<channel>";
echo "<title>".$rss_title."</title>";
echo    "<link>".$rss_link."/rss.php"."</link>";
echo " <description>".$rss_description."</description>";
echo   "<pubDate>". $rss_pub_date."</pubDate>";


Couldn’t agree more! If the file contains PHP code its extension must be .php. No discussion there :slight_smile:

PHP always parses files you include() as PHP. Just tried it with renaming a .php file to .txt and then include that; PHP is still executed just fine.

So I’d say it’s a short opentag problem. Replace <? at the start of the rss.inc with <?php and it should work.

the rss doesn’t work anymore

Perhaps if you were to define that for us, or show the smallest sample of html source code it outputs?