Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Rss Feed with Perl issue 2

Status
Not open for further replies.

ednit

Technical User
Jan 31, 2006
16
US
I am trying to create a rss feed for stored database information with the below script.

This setup works on one of my websites (the same hosting account/server) but will not work on another for some reason. What it does is offers the results in a download instead of displaying them in the browser. (i.e. you try to view the feed: & you download the results) I've had this problem with scripts before when I didn't declare the headers properly, but I can't see the error here.

Also - nothing shows up in the error log.



Code:
#!/usr/bin/perl


require "/home/example/db.pm";


use CGI::Carp qw(fatalsToBrowser);

#print "content-type: text/html\n\n";

print "content-type: application/rss+xml\n\n";

sub opendb {
  use DBI;
  $dbh = DBI->connect("DBI:mysql:$dbname:$host","$dbuser","$dbpass");
return; }

sub closedb {
  $dbh->disconnect();
  return; }

print qq~
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<rss version="2.0">
<channel>
<title>EXAMPLE TITLE</title>
<description>EXAMPLE DESC</description>
<link>[URL unfurl="true"]http://www.example.com</link>[/URL] ~;

&opendb;
$lo = $dbh->prepare("select id,title,description from links order by id DESC");
$lo->execute();
while ($qw = $lo->fetchrow_hashref()) {

$gl_id = $qw->{'id'};
$gl_title = $qw->{'title'};
$gl_description = $qw->{'description'};


$gl_description =~ s|\'|\&\#39\;|g;


print qq~
<item>
<title>$gl_title</title>
<description>$gl_description</description>
<link>[URL unfurl="true"]http://example.com/dl.link?go=$gl_id</link>[/URL]
</item>
~;
}
&closedb;
print qq~
</channel>
</rss>
~;

exit;

The .htaccess file:

Code:
DirectoryIndex index.xml
Options ExecCGI
AddType application/x-httpd-cgi .htm .link .xml

As I stated, this works on a different website on the same server. . . if anybody sees something, please let me know.

Thanks.
 
Have you tried a different file extension other than .xml?
I'm guessing here a bit but I wonder if the webserver is doing something silly with your headers because it thinks it knows the file extension.
Also, have you tried something like wget, curl or LWP::UserAgent to collect the page manually and examine the headers that the webservers return. If you collect one from each you could "diff" them to see if that's the problem.


Trojan.
 
Trojan, I had tried using a .htm & .cgi extension on the file with the same results. When I try swapping the content type to text/html the page is blank. As far as writing something to see what headers return, I may have to try that if the suggested module doesn't work. Not sure where the issue lies, my other feeds setup the same way still are working.

ishnid, that module looks like it would work a lot better for what I am trying to do, I've asked my web host to install it. Thanks for pointing it out to me.

Thanks for your inputs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top