Construct a Dynamic RSS Feed With PHP and MySQL

Notice: Anywhere the thing is be sure to insert your websites url set up of .

Just about everywhere I seem I can discover tutorials but seldom are they full. The tutorial I am about to generate is meant to get an entire tutorial.Articles at Dehumidifier Feed Confident you may incorporate more solutions to your RSS file itself but what I indicate by complete is it will get the job done for anybody when the principals that happen to be outlined right here are followed. Without even further hold off lets bounce proper into create a dynamic RSS feed making use of PHP and MySQL

To start our PHP centered RSS feed we have to do just one minimal detail initial. Acquire a glance at your “.htaccess” file and that is typically situated in the basis directory of internet server. It’s the file that is certainly employed for accomplishing URL rewrites, 301 redirects and so forth. Each and every Apache server must have it so try to look for it. In case you are working with dreamweaver a simple to receive the file is usually to make it from the web-site manager, i.e. right-click and make a new file. Rename the file “.htaccess” then correct simply click on the freshly produced file and click on “Get”. Yet again this is often only for end users of Dreamweaver. I am producing this additional intricate than it should be. Look for.htaccess with your web server root. Adequate said

Once we’ve our.htaccess file uncovered we must come up with a transform. Since our RSS file might be of your PHP extension i.e. rss.php and not of your xml type. We want.htaccess to grasp that files together with the style.xml shoule be interpreted as.php documents. To do that we enter the next inside our.htaccess file:

AddType application/x-httpd-php.xml

With our.htaccess file able to go we now have to commence creating the PHP for our RSS feed. Our file will likely be damaged into four sections. The first could be the header which tells the browser that the file is of variety XML. The 2nd portion may be the head of our RSS file. Its everything that you choose to could make static about the channel, i.e. the essential data relevant to the RSS feed. Our 3rd sections is where it will get nifty. We produce a database relationship and utilize it to develop our RSS feed. We then need to loop as a result of every single of the products we would like in our databases and output them as xml. Ultimately our fourth portion is all the output that may be essential to close the channel. You can find small to it aside from a few echo commands but it is a individual part in its individual insignificant way.

Initially we have to develop a new php file, I chose to call mine rss.php, you could identify yours regardless of what you prefer. As soon as we now have our file open we begin with our to start with part:

//Set XML header for browser

header(‘Content-type: text/xml’);


Right before we do just about anything we would like to send out a concept for the browser that informs it that it’s working by having an XML file. If we did not pass this information for the browser our dynamic RSS feed would not operate. As simple as it sounds that’s it for our 1st component of our RSS file.

Inside our next portion we must get started generating the construction of our XML file. You’ll find couple of approaches to do that. 1 is using the echo command. Another is thru the use of variables. I have used each and individually prefer the variable process as it seems less difficult in my intellect. As a result that is the process I’ll show. Here is our code (it contains the code from our 1st portion):

Comments are closed.