Create Dynamic XML RSS Feed / Sitemap File Using PHP And MYSQL

Share:

Create Dynamic XML RSS Feed / Sitemap File Using PHP And MYSQL. In the previous post we have learned how to create a simple sitemap / RSS feeds manually. For this tutorial, it will be harder because we will create dynamic XML RSS Feed / Sitemap file using PHP and MYSQL.
Create Dynamic XML RSS Feed / Sitemap File Using PHP And MYSQL Create Dynamic XML RSS Feed / Sitemap File Using PHP And MYSQL
The advantages of dynamic XML RSS Feed / Sitemap files are the automatic updates when new posts are published in our website. So we don’t need to take the time to edit the RSS Feed / Sitemap of our website.

Create Dynamic XML RSS Feed / Sitemap File Using PHP And MYSQL

Immediately, following the tutorial how to create dynamic XML RSS Feed / Sitemap file using PHP and MYSQL :

Download Now Create Dynamic XML RSS Feed / Sitemap File Using PHP And MYSQL

MYSQL Database For Create Dynamic XML RSS Feed / Sitemap File
The first is to create a database as a place to store items such as the title of each post, url and the description. Copy MYSQL database below:

CREATE TABLE 'sitemap' (
  'id' int(11) NOT NULL auto_increment,
  'title' varchar(500) NOT NULL,
  'description' varchar(250) NOT NULL,
  'link' varchar(500) NOT NULL,
  PRIMARY KEY  ('id')
) ;

Create PHP Script For Create Dynamic XML RSS Feed / Sitemap File
The second step is to create an xml file using php script. Copy and paste the php script below into notepad or adobe dreamweaver :
dynamic-sitemap-rss-feed.php

<?php  
header('Content-Type: text/xml');  
echo '<?xml version="1.0" encoding="ISO-8859-1"?>  
<rss version="2.0">  
<channel>  
<title>My Website Name</title>  
<description>A description of the feed</description>  
<link>Website Address</link>';  
$user = 'root';
$pswd = '';
$pdo = new PDO("mysql:host=localhost;dbname=databasename", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
  $query = $pdo->prepare("select * from sitemap order by id desc LIMIT 0 , 10");
$query->execute();
while($sitemap = $query->fetch()){     
    echo '<item>  
          <title>'.$sitemap[title].'</title>  
          <description>'.$sitemap[description].'</description>  
          <link>'.$sitemap[link].'</link>  
      </item>';  
}  
echo '</channel> '; 
echo '</rss>';  
?>  

Rewrite Format File From Dynamic XML RSS Feed / Sitemap
In the second step, we’ve managed to create a sitemap file. Although the look of the file is the same as the file sitemap / rss feed on other websites but there was something odd like that filename is a php file. Should sitemap / RSS feed in the form of xml file. We can still read the content contained in the sitemap / RSS feed file but what php files can be read by a spider bot. Is not it by default should use .xml format ?

So that it is not always a doubt for us that the most appropriate step is to rewrite the file format of sitemap / RSS feeds them. In the .htaccess file, you add the following script. The sitemap format will change from dynamic-sitemap-rss-feed.php to dynamic-sitemap-rss-feed.xml

RewriteEngine on
RewriteRule ^dynamic-sitemap-rss-feed\.xml$ dynamic-sitemap-rss-feed.php [NC,R]

Don’t forget, after a dynamic sitemap / RSS Feed has been successfully created, you must register to Webmaster Tools so that search engine spider bots can crawl soon all post in the dynamic sitemap / RSS Feed item.
You can try it and good luck 🙂
Thanks for reading How To Create And Build Sitemap / RSS Feed XML Files For Website

[Tutorial.World.Edu]

One thought on “Create Dynamic XML RSS Feed / Sitemap File Using PHP And MYSQL

Leave a Reply

Your email address will not be published. Required fields are marked *