developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
New
 
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




Nominate the Best Products or Technologies for Developer.com Product of the Year!




Developer Jobs

Be a Commerce Partner














 


Developer News -
Metasploit 3.2 Offers More 'Evil Deeds'    October 8, 2008
'Thank You Apple. Seriously.'    October 8, 2008
The Buzz: BlackBerry App Store Seen Next    October 7, 2008
Is .NET on Linux Finally Ready?    October 6, 2008
Free Tech Newsletter -

Creating a Custom RSS Feed Aggregator
By W. Jason Gilmore

Go to page: Prev  1  2  

The PHP Script

The final task is to create the script that will display the user's chosen RSS feeds. This script, titled myrss.php, is surprisingly simple, consisting of just two main components:

  • Login: The user will need to log in to view his customized feeds. This is accomplished by using a simple form and some logic that will confirm the supplied e-mail address and password.
  • RSS Aggregation and Delivery: Assuming a valid login (or valid session; see next paragraph), we'll use the Magpie RSS Parser to display the user's chosen RSS feeds.

To save users the hassle of having to repeatedly log in every time they need an RSS "fix," I make use of PHP's session-handling feature. Once successfully logged in, the user's unique identifier is stored as a session variable for later retrieval. Keep in mind that the storage duration is entirely dependent upon how your PHP installation's session functionality is configured.

Listings 1-1 and 1-2 offer the commented code for both components. Both components are assembled and available for viewing via a link posted at the conclusion of Listing 1-2.

Listing 1-1: The Login Component

// Start or continue a session

session_start();


// Has the user

if (! isset($_SESSION['userid']))
{

   if (! isset($_POST['email']))
   {

      echo "<form action='myrss.php' method='post'>";
      echo "Email:<br />";
      echo "<input type='text' name='email' size='20'
                   maxlength='55' value='' /><br />";
      echo "Password:<br />";
      echo "<input type='password' name='pswd' size='20'
                   maxlength='20' value='' /><br />";
      echo "<input type='submit' value='login'>";
      echo "</form>";

   } else {

      mysql_connect("localhost","aggregator","secret");
      mysql_select_db("rssfeeds");

      $email = $_POST['email'];
      $pswd = md5($_POST['pswd']);

      $query = "SELECT rowID, email, pswd FROM user 
                WHERE email='$email' AND '$pswd'";
      $result = mysql_query($query);

      if (mysql_numrows($result) != 1)
      {
         echo "<p>Could not login!</p>";
      } else {
         list($rowID, $email, $pswd) = mysql_fetch_row($result);
         $_SESSION['userid'] = $rowID;
      }

      mysql_close();

   } // end isset[email]

}

Listing 1-2. The RSS Aggregation and Delivery Component

if (isset($_SESSION['userid'])) {

   require_once("rss_fetch.inc");

   mysql_connect("localhost","aggregator","secret");
   mysql_select_db("rssfeeds");	

   $userID = $_SESSION['userid'];

   $query = "SELECT rss.title, rss.url
             FROM rssfeed AS rss, user_to_rss_feed as userrss
             WHERE userrss.userid='$userID' 
             AND rss.rowID=userrss.rssid";

   $result = mysql_query($query);

   while(list($title,$url) = mysql_fetch_row($result)) 
   {

      $url = "$url";
      $rss = fetch_rss( $url );

      echo "<strong>" . $rss->channel['title'] . "</strong><p>";
      echo "<ul>";
      foreach ($rss->items as $item) 
      {
         $href = $item['link'];
         $title = $item['title'];
         echo "<li><a href=$href>$title</a></li>";
      }

      echo "</ul>";

   }

   mysql_close();

}

View the complete script here

Figure 1-1 depicts the login form.

Figure 1-2 depicts a typical display of requested RSS feeds.

Conclusion

I welcome questions and comments! E-mail me at jason@wjgilmore.com. I'd also like to hear more about your experiences integrating RSS feeds with PHP and MySQL!

About the Author

W. Jason Gilmore (http://www.wjgilmore.com/ ) is an Internet application developer for the Fisher College of Business. He's the author of the upcoming book, PHP 5 and MySQL: Novice to Pro, due out by Apress in 2004. His work has been featured within many of the computing industry's leading publications, including Linux Magazine, O'Reillynet, Devshed, Zend.com, and Webreview. Jason is also the author of A Programmer's Introduction to PHP 4.0 (453pp., Apress). Along with colleague Jon Shoberg, he's co-author of "Out in the Open," a monthly column published within Linux magazine.

# # #

Go to page: Prev  1  2  

Previous article: Searching Active Directory with Perl


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


XML Archives








JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
Avaya Article: Call Control XML - Powerful, Standards-Based Call Control
Tripwire Whitepaper: Seven Practical Steps to Mitigate Virtualization Security Risks
Internet.com eBook: The Pros and Cons of Outsourcing
Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
Go Parallel Article: Getting Started with TBB on Windows
HP eBook: Storage Networking , Part 1
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
HP Video: Is Your Data Center Ready for a Real World Disaster?
Microsoft Partner Portal Video: Microsoft Gold Certified Partners Build Successful Practices
HP On Demand Webcast: Virtualization in Action
Go Parallel Video: Performance and Threading Tools for Game Developers
Rackspace Hosting Center: Customer Videos
Intel vPro Developer Virtual Bootcamp
HP Disaster-Proof Solutions eSeminar
HP On Demand Webcast: Discover the Benefits of Virtualization
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Microsoft Download: Silverlight 2 Software Development Kit Beta 2
30-Day Trial: SPAMfighter Exchange Module
Red Gate Download: SQL Toolbelt
Iron Speed Designer Application Generator
Microsoft Download: Silverlight 2 Beta 2 Runtime
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES