Create a custom RSS feed collector

xiaoxiao2021-03-06  55

A rich site summary feed, its abbreviation RSS is more famous, it is a great example of how XML has a major impact on information consumption. This XML term is a popular format for summarizing information, which is typically, but not specially facing news, including title, summary, authors and release dates. Establishing and assigning RSS feeds becoming increasingly popular, there are several reasons: · Competition: With the continued growth of the number of Web sites competed for customers, the choice of choice for their information to the consumer is always considered in. · Information overload: It is clear that consumers have found them more and more dependent on growing Web sites. That is, the linear navigation method from a site to another has not cut their dependencies. Browse the site summary and do not usually transfer charts, advertisements, and additional foreign materials, is an important way for the minimum investment time and quickly filtering the required information. · Universality: Based on XML-based format clear division of data and expressions, it is easy to convert to widely adapted to different needs of different media distribution (standard web browsers, cell phone, paper, email, etc.). Although the use of RSS feeds has been classified into the elite, they seem to have occurred everywhere. Yahoo!, Christian Science Monitor, CNet News.com, and the BBC have recently available in the WEB site that RSS feeds to their readers. Note: Those readers who are completely unfamiliar with RSS are loaded with Yahoo's technical feed (http: //rss.news.yahoo.com/rss/tech) to your browser in a minute. You can quickly recognize the organization's good data format, which will lend yourself to the expression of the expression, which is a typical thing of XML terminology. For a complete discussion of this topic, you will have a quick search on your favorite search engine; you will find more guidelines more than your keyboard operation. Directory MAGPIE RSS RSS feed MySQL Database PHP Script Conclusion In this article, I will explain how to use PHP, MySQL database servers, and Magpie RSS Parser to provide custom RSS feed services to your web site users. Although I hope that you have at least the basic experience of using PHP and MySQL, but for beginners, examples should be very easy to understand. Because most people in you may not be familiar with Magpie RSS Parser, I will provide some additional information on this important tool. Magpie RSS MAGPIE RSS Parser is created by Kellan Elliott-Mccrea in 2002 to make sure that he perceived does not have a real PHP-based RSS collection solution. As a result, there is an excellent feasible tool that provides a group of useful features, including: • Object-oriented design: object-oriented, modular code allows you to integrate collection features into previous applications . · Extreme configurability: MAGPIE collection and cache behavior can be modified by a good through configuration policy. · Feed cache: This very cool feature can locally cache RSS feed (on the server) to save bandwidth and enhance the performance of the application because it is released under GPL License, so you don't have to save money, as long as you are willing, and The terms and conditions of the license can be free to use this software. It only needs to use XML (Exppat to support new version of PHP (4.0 ). RSS feed let us start from the content of the application. Which type of RSS do you like to provide to your users? Finding RSS feeds seems to be as easy to read your favorite search engine: Just enter "RSS" and some other selection topics such as "Technology," Science, "or" Sports. "And so on.

For a lazy person (there is no bad feature in the programming industry), many RSS collection players bought by Web. Feedster (http://www.feedster.com/) are also one of my personal preferences. For this guide, I will use the following feed: · Yahoo! Top Stories (http://rss.news.yahoo.com/rss/topstories) · MSDN, Recent Technical Articles (http://msdn.microsoft.com/ RSS.XML) · Infoworld Latest News (http://www.infoworld.com/rs/news.rdf) · PcWorld Latest News (http://rss.pcworld.com/rs/latestnews.rs) · Eweek Technology News (http://rssnewsapps.ziffdavis.com/tech.xml) You should remember: Some RSS publishers need to license to allow you to feed their feed for commercial purposes. Therefore, you will always look at any of the terms of use before installation. Please record the feed position, title, and URL, you are willing to record the description. In the next section, we will create a database table for favorites this information. MySQL Database To implement our custom RSS service, only three database tables are required. This part, I will introduce these three forms. RSSFeed The first table RSSFEED will store RSS feed information. For example, we only store three items: unique ID, title and URL. In a more complex application, you might store other details, as described, feed added to the date of the collector, the number of waiting seconds between the retrieval, and other related information. Mysql> Create Table Rssfeed

> ROWID TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,

> Title Varchar (150) Not Null,

> URL VARCHAR (150) Not null,

> Primary Key (RowID)

>);

Table 1-1 shows the table content after adding the selected RSS feed:

User Second Table USER stores information about the user using the RSS collector. Each user can only have a unique logo so that we can provide custom services; if so, each user can be tagged with a simple integer value. You need to log in before the user manages his preferred feed and browsses feed, so his email and password will save. For safety, the password can be saved as a unsolvable hash table consisting of 32 characters. In addition, just as the RSS form, in real applications, the user form can become more complicated; however, the necessary part of our collection mechanism can still be found in our form.

Mysql> Create Table User

> ROWID Smallint Unsigned Not Null Auto_Increment,

> Email Varchar (55) Not NULL,

> pswd varchar (32) Not null,

> Primary Key (RowID)

>);

For the simplicity of the example, Table 1-2 shows an example of user information stored in the table: Table 1-2: User Information Example

User_to_rss_feed Third Table User_to_RSS_FEED, link the user with the RSS feeds they choose. This form has two columns: UserID and RSSID. UserID tag users; RSSID tag RSS feed.

MySQL> CREATE TABLE USER_TO_RSS_FEED (> Userid Smallint Unsigned Not Null Auto_Increment,

> rsSID tinyint unsigned not null

>);

Table 1-3 provides analog of the form of content after our users have selected their favorite feed. Table 1-3: User / RSS feed mapping

The last task of the PHP script is to create a script that displays the RSS feed selected by the user. The title of this script is myrss.php, and he is incredible, only two main components: · login: The user needs to log in to browse his custom feed. This can be completed by using a simple table and some confirmation of the email address and password logic. · RSS AGGREGATION AND DELIVERY: If a valid login (or a valid session; see next), we will use the Magpie RSS Parser to display the RSS feed selected by the user. To avoid user complaints to log in every time you need RSS "FIX," and I use PHP's session period processing feature. Once successful login, the user's unique flag is stored as a session period to be retrieved later. Remember, the storage period is completely dependent on how you configure your PHP installation session period feature. Listings 1-1 and 1-2 provide annotation code for both components. Both components are equipped with and can be used to browse, and the browsing feature can be implemented by setting a link at the end of Listing 1-2. Listing 1-1: Login component

// Start or Continue a session

session_start ();

// HAS THE User

IF (! isset ($ _ session ['userid']))

{

IF (! isset ($ _ post ['email'])))

{

echo "

";

Echo "email:
";

echo "

Maxlength = '55 'Value =' '/>

Echo "Password:
";

echo "

Maxlength = '20 'value =' '/>

echo "";

Echo "";

} else {

MySQL_Connect ("LocalHost", "Aggregator", "Secret");

MySQL_SELECT_DB ("Rssfeeds");

$ EMAIL = $ _POST ['email'];

$ PSWD = MD5 ($ _ post ['pswd']);

$ query = "SELECT ROWID, Email, Pswd from userwhere email = '$ email' and '$ pswd'";

$ result = mysql_query ($ query);

IF (MySQL_NUMROWS ($ result)! = 1)

{

echo "

could not login! ";

} else {

List ($ ROWID, $ EMAIL, $ PSWD) = mysql_fetch_row ($ results);

$ _SESSION ['Userid'] = $ ROWID;

}

MySQL_Close ();

} // End isset [email]

}

Listing 1-2. RSS Collection and Putting Components

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 rs, user_to_rs_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 "". $ rss-> channel ['title']. "

";

echo "


New Post(0)