I am currently developing a dynamic RSS feed that will automatically pull articles from a MySQL database. The code is below
<?php
//Include the post retreival script
require_once '../phpScripts/rss_db_setup.php';
//Set the content type
header('Content-type: text/xml');
//Set up the RSS feed information
echo '<?xml version="1.0" encoding="ISO-8859-1"?>'.
'<rss version="2.0">'.
'<channel>'.
'<title>Company Name</title>'.
'<link>http://www.company.ca</link>'.
'<description></description>'.
'<category></category>';
//Retreive posts from the database
$rssData = new rssData();
echo $rssData->generateFeed($dbcon);
//Close the feed
echo '</channel></rss>';
?>
I am wondering whether this file should be saved as a .xml or a .php? I have added the following line to my .htaccess file, but do not really understand exactly how it works
AddType application/x-httpd-php .xml
Is this a correct way to do this? Or should I use another htaccess function such as modRewrite, or use a CRON job to generate a new .xml every day or so?
With the
AddType application/x-httpd-php .xmlline, Apache will be able to serve XML files containing some PHP code inside. So you can save this file as a .xml, the PHP code will be interpretedPerhaps you should add a cache manager in order to avoid generating the same feed when there is no new article?