Hi I have problem with rss feed I have made with PHP Firefox is understanding my code and displayes the feed, but rss validators and IE8 are not working with it Here is my code: <?php require("dbconnect.php"); // else { $website_URLq=MYSQL_FETCH_ARRAY(mysql_query("SELECT * FROM settings WHERE set_name='website_URL' ")); $website_URL=$website_URLq['set_value']; header("Content-Type: application/rss+xml; charset=ISO-8859-1"); echo ('<?xml version="1.0" encoding="ISO-8859-1" ?>'); ?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>website title RSS FEED</title> <link>http://mywebsite.net</link> <description>The newest changes to customers and orders.</description> <atom:link href="<?php echo $website_URL;?>/rss_feed.php" rel="self" type="application/rss+xml" /> <?php $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 "); while($row=mysql_fetch_array($result)){ //some php code here $item="<item> <guid isPermaLink='false'>$guide</guid> <title>$title</title> <link>$link</link> <description>$desc</description> </item>"; echo $item; } } ?> </channel> </rss> PHP: When I use validators, it seems the last 2 lines: </channel> </rss> are the first things they see and return parse error Could anyone help me solve this problem? Thanks in advance
One thing that I've found with rss and IE is the fact of white spaces in files that shouldn't be. It will fault out. So make sure that you have no extra lines that would create white spaces in your database file, and maybe tighten up the formatting with this as well. If you still have issues - repost here and I will see what I can do.
1) could we see the rest of your code, so we can see what that ELSE is in response too? 2) some actual code indentation on your PHP wouldn't hurt... 3) you don't need parenthesis on ECHO 4) why are you using 1990's style character encoding? 5) if often helps to do all your processing BEFORE you start your output, so it's sent as larger 'chunks' should the server be multi-chunking. 6) avoid string additions when comma delimits are faster and workable. It's less memory overhead. 7) Avoid making unnecessary variables -- particularly inside a loop. 8) Avoid using double quotes for echo, they're slower than singles (only 1-2%, but really, 1-2% faster by not hitting an extra key?), and also can make a right mess of things. 9) PHP is a case sensitive language, your upper-case MYSQL_FETCH_ARRAY should be throwing an error. 10) I'd really have to see the entire code to be sure, since all we're seeing is after the else, but are you 100% sure that NOTHING is being output prior to that header() being sent? As a rule of thumb, I try to avoid opening and closing PHP with <?php ?> unnecessarily... I've rarely had it be anything but a confusing mess. If I was writing that same thing, it would probably go more like this: else { $website_URLq=mysql_fetch_array(mysql_query("SELECT * FROM settings WHERE set_name='website_URL' ")); $website_URL=$website_URLq['set_value']; header("Content-Type: application/rss+xml; charset=UTF-8"); echo ('<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>website title RSS FEED</title> <link>http://mywebsite.net</link> <description>The newest changes to customers and orders.</description> <atom:link type="application/rss+xml" href="',$website_URL,'/rss_feed.php" rel="self" />'; $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 "); while ($row=mysql_fetch_array($result)) { //some php code here -- well that's vague echo ' <item> <guid isPermaLink="false">',$guide,'</guid> <title>',$title,'</title> <link>',$link,'</link> <description>',$desc,'</description> </item>'; } echo ' </channel> </rss> } Code (markup): Though again, hard to say without seeing the rest of it. I suspect that those other systems are only getting the closing tags from the bottom of the file as if whatever the case is BEFORE the ELSE { is what's running -- which is why I moved them INSIDE the ELSE{} Really I think that's what's going on, in everything but firefox, whatever is in the code above your partial snippet is what's tripping. Oh, and if you're 'some php code here' is just wasting time copying $row to extra variables for no reason other than to waste memory and execution time, CUT IT OUT! -- really, I'm seeing a LOT of people doing that these days, and it's like "land's sake, why?!?" -- edit -- also forgot, NOT that you should be using mysql_ statements anymore either, they're deprecated in favor of mysqli or PDO, USE THEM! Also, I didn't think IE8 did anything meaningful with RSS feeds... Or am I just that out of touch with using IE as a day to day browser?
Thank you very much deathshadow Problem solved. the If (before else) was checking a session variable for authentication. I am going to use another method for authentication like http://...rss.php?user=****&auth=***