I'm trying to create a custom RSS feed for my website using PHP and I've hit a snag.<br /><br />The script I'm using generates valid RSS feeds (I've tested them) and they do work perfectly when I run one such feed as an .XML file, but my situation requires that they run as a .PHP file. I know this is possible because I have visited several sites that do this. They have a .PHP file that serves as a valid RSS feed.<br /><br />How do I do this?<!--content-->
Here is one example of the implementation I am talking about.<br /><br /><a href="http://www.archive.org/services/collection-rss.php" target="_blank">http://www.archive.org/services/collection-rss.php</a><br /><br />As you can see, this is a working RSS feed. And, since it's PHP. you can do have it do things you can't normally do in a plain XML file (for example, you could subscribe to a specific category by adding a category string to the URL, if that were allowed).<br /><br />The feed I'm trying to create requires that same kind of functionality.<br /><br />At present, my browser displays a blank screen when I attempt to use my own "rss.php" file, and all RSS readers see it as invalid.<!--content-->
There's no longer a need for a reply. After working at for a while I managed to find the solution on my own.<!--content-->
What was the problem and its solution? Other people who read this topic could benefit from your experience. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /> <br /><br />Without a link to the feed you're trying to create (and possibly the code in your script), it is very difficult for anyone to help you figure out what is wrong.<br /><br />I don't know how you're testing your feed, but I was going to suggest running your feed through the <a href="http://feedvalidator.org/" target="_blank">Feed Validator</a> to see if it identified any problems.<br /><br />You did not say what the file name of your feed was, but if it ended in '.rss.php', the server would see this as a file with two extensions and it could try to serve it as a .rss file instead of a .php file.<!--content-->
<!--quoteo(post=152996:date=Oct 23 2005, 03:49 AM:name=TCH-David)--><div class='quotetop'>QUOTE(TCH-David @ Oct 23 2005, 03:49 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=152996"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->What was the problem and its solution? Other people who read this topic could benefit from your experience. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />You're absolutely right!<br /><br />What I was trying to do was create a PHP script that can create a customized RSS feed on the fly, depending on what the browser has in its query string. I ran into several problems, but managed to solve them with the help of my two biggest assets: coffee and google.<br /><br />Here's the code I wrote:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br />header('Content-type: application/xml');<br /><br />if ($_POST["id"])<br />$id = $_POST["id"];<br />else if ($_GET["id"])<br />$id = $_GET["id"];<br /><br />if ($_POST["synch"])<br />$synch = $_POST["synch"];<br />else if ($_GET["synch"])<br />$synch = $_GET["synch"];<br /><br />if ($_POST["data"])<br />$data = $_POST["data"];<br />else if ($_GET["data"])<br />$data = $_GET["data"];<br /><br />$day = $id/214746;<br />$month = $synch/8562;<br />$year = $data/634;<br /><br />$date2 = "$year-$month-$day";<br />$date1 = date("Y-m-d");<br />$dateOne = explode("-",$date1);<br />$dateTwo = explode("-",$date2);<br />$dateOne = (Mktime(00, 00, 00, $dateOne[1], $dateOne[2], $dateOne[0]));<br />$dateTwo = (Mktime(00, 00, 00, $dateTwo[1], $dateTwo[2], $dateTwo[0]));<br />$numberOfDays = round(($dateOne - $dateTwo) / 86400);<br />if ($numberOfDays < 0) $numberOfDays = $numberOfDays * -1;<br />if ($id == 0) $numberOfDays = -1;<br />if ($data == 0) $numberOfDays = -1;<br />if ($synch == 0) $numberOfDays = -1;<br /><br />if ($numberOfDays >=0)<br />readfile('http://www.mysite.net/rss/header.txt');<br /><br />if ($numberOfDays >=0)<br />readfile('http://www.mysite.net/rss/feed1.txt');<br /><br />if ($numberOfDays >= 1)<br />readfile('http://www.mysite.net/rss/feed2.txt');<br /><br />if ($numberOfDays >= 2)<br />readfile('http://www.mysite.net/rss/feed3.txt');<br /><br />if ($numberOfDays >= 3)<br />readfile('http://www.mysite.net/rss/feed4.txt');<br /><br />if ($numberOfDays >=0)<br />readfile('http://www.mysite.net/rss/footer.txt');<br /><br /><br />?><!--c2--></div><!--ec2--><br /><br />This script does a few things.<br /><br /><b>1.</b> It reads the exact date in which you first subscribed to the feed. This information is read from the query string, which is automatically generated by the server when you browse the site which contains the feed link.<br /><br /><b>2.</b> It compares the subscribed date to the present date<br /><br /><b>3.</b> It then delivers content depending on how many days have passed.<br /><br />The problem I was having (getting the script to be recognized as a valid RSS feed) was because the server has php scripts under a certain mime type (the mime type for any RSS feed needs to be "application/xml" so even though the content of the feed itself was valid it was being treated as an html document, not an xml document, and I couldn't change the mime type for php files across the whole site using cPanel (doing that would break the whole website, turning it into one big xml error message).<br /><br />As you can see, I fixed that.<br /><br />The .txt files referenced in the script contain the actual feed information. header.txt and footer.txt contain the info for the feed itself and feed1.txt - feed4.txt contain the separate items in the feed.<br /><br />I'm thinking of modding the script to recognize more times. Currently this script only reads days but, Ideally, I'd like it to also recognize minutes and hours.<br /><br />This is an experiment I'm working on for my site. I intend to create content (namely, stories) where you'll be able to subscribe to the content, and the information in the feed will be sent to you depending on how long you stay subscribed. For example: if I had a book online one could subscribe to the book and receive the separate chapters in his RSS reader, in order, according to a set interval. It could be one chapter a day, or one chapter every few hours, or whatever.<!--content-->
By the way. Feeds generated by this script register as fully valid on <a href="http://feedvalidator.org/" target="_blank">Feed Validator</a>. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
Thanks for the explanation! I'm sure it will help out other family members who are looking to do the same type of thing!<!--content-->
Here is one example of the implementation I am talking about.<br /><br /><a href="http://www.archive.org/services/collection-rss.php" target="_blank">http://www.archive.org/services/collection-rss.php</a><br /><br />As you can see, this is a working RSS feed. And, since it's PHP. you can do have it do things you can't normally do in a plain XML file (for example, you could subscribe to a specific category by adding a category string to the URL, if that were allowed).<br /><br />The feed I'm trying to create requires that same kind of functionality.<br /><br />At present, my browser displays a blank screen when I attempt to use my own "rss.php" file, and all RSS readers see it as invalid.<!--content-->
There's no longer a need for a reply. After working at for a while I managed to find the solution on my own.<!--content-->
What was the problem and its solution? Other people who read this topic could benefit from your experience. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /> <br /><br />Without a link to the feed you're trying to create (and possibly the code in your script), it is very difficult for anyone to help you figure out what is wrong.<br /><br />I don't know how you're testing your feed, but I was going to suggest running your feed through the <a href="http://feedvalidator.org/" target="_blank">Feed Validator</a> to see if it identified any problems.<br /><br />You did not say what the file name of your feed was, but if it ended in '.rss.php', the server would see this as a file with two extensions and it could try to serve it as a .rss file instead of a .php file.<!--content-->
<!--quoteo(post=152996:date=Oct 23 2005, 03:49 AM:name=TCH-David)--><div class='quotetop'>QUOTE(TCH-David @ Oct 23 2005, 03:49 AM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=152996"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->What was the problem and its solution? Other people who read this topic could benefit from your experience. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />You're absolutely right!<br /><br />What I was trying to do was create a PHP script that can create a customized RSS feed on the fly, depending on what the browser has in its query string. I ran into several problems, but managed to solve them with the help of my two biggest assets: coffee and google.<br /><br />Here's the code I wrote:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php<br /><br />header('Content-type: application/xml');<br /><br />if ($_POST["id"])<br />$id = $_POST["id"];<br />else if ($_GET["id"])<br />$id = $_GET["id"];<br /><br />if ($_POST["synch"])<br />$synch = $_POST["synch"];<br />else if ($_GET["synch"])<br />$synch = $_GET["synch"];<br /><br />if ($_POST["data"])<br />$data = $_POST["data"];<br />else if ($_GET["data"])<br />$data = $_GET["data"];<br /><br />$day = $id/214746;<br />$month = $synch/8562;<br />$year = $data/634;<br /><br />$date2 = "$year-$month-$day";<br />$date1 = date("Y-m-d");<br />$dateOne = explode("-",$date1);<br />$dateTwo = explode("-",$date2);<br />$dateOne = (Mktime(00, 00, 00, $dateOne[1], $dateOne[2], $dateOne[0]));<br />$dateTwo = (Mktime(00, 00, 00, $dateTwo[1], $dateTwo[2], $dateTwo[0]));<br />$numberOfDays = round(($dateOne - $dateTwo) / 86400);<br />if ($numberOfDays < 0) $numberOfDays = $numberOfDays * -1;<br />if ($id == 0) $numberOfDays = -1;<br />if ($data == 0) $numberOfDays = -1;<br />if ($synch == 0) $numberOfDays = -1;<br /><br />if ($numberOfDays >=0)<br />readfile('http://www.mysite.net/rss/header.txt');<br /><br />if ($numberOfDays >=0)<br />readfile('http://www.mysite.net/rss/feed1.txt');<br /><br />if ($numberOfDays >= 1)<br />readfile('http://www.mysite.net/rss/feed2.txt');<br /><br />if ($numberOfDays >= 2)<br />readfile('http://www.mysite.net/rss/feed3.txt');<br /><br />if ($numberOfDays >= 3)<br />readfile('http://www.mysite.net/rss/feed4.txt');<br /><br />if ($numberOfDays >=0)<br />readfile('http://www.mysite.net/rss/footer.txt');<br /><br /><br />?><!--c2--></div><!--ec2--><br /><br />This script does a few things.<br /><br /><b>1.</b> It reads the exact date in which you first subscribed to the feed. This information is read from the query string, which is automatically generated by the server when you browse the site which contains the feed link.<br /><br /><b>2.</b> It compares the subscribed date to the present date<br /><br /><b>3.</b> It then delivers content depending on how many days have passed.<br /><br />The problem I was having (getting the script to be recognized as a valid RSS feed) was because the server has php scripts under a certain mime type (the mime type for any RSS feed needs to be "application/xml" so even though the content of the feed itself was valid it was being treated as an html document, not an xml document, and I couldn't change the mime type for php files across the whole site using cPanel (doing that would break the whole website, turning it into one big xml error message).<br /><br />As you can see, I fixed that.<br /><br />The .txt files referenced in the script contain the actual feed information. header.txt and footer.txt contain the info for the feed itself and feed1.txt - feed4.txt contain the separate items in the feed.<br /><br />I'm thinking of modding the script to recognize more times. Currently this script only reads days but, Ideally, I'd like it to also recognize minutes and hours.<br /><br />This is an experiment I'm working on for my site. I intend to create content (namely, stories) where you'll be able to subscribe to the content, and the information in the feed will be sent to you depending on how long you stay subscribed. For example: if I had a book online one could subscribe to the book and receive the separate chapters in his RSS reader, in order, according to a set interval. It could be one chapter a day, or one chapter every few hours, or whatever.<!--content-->
By the way. Feeds generated by this script register as fully valid on <a href="http://feedvalidator.org/" target="_blank">Feed Validator</a>. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
Thanks for the explanation! I'm sure it will help out other family members who are looking to do the same type of thing!<!--content-->