简体   繁体   中英

How to link RSS feed created in php mysql

I have created an RSS feed php file in php which is connected to MySQL. Based on ID, if you click on RSS links it will generate an RSS feed for everyone. But I want to know how can I link my RSS feed php file to the RSS link. Here is my PHP file code:

<html>
<head>
<title>New Feed</title>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1" />
</head>
<body>
<?php
Function NewFeed($DingoID,$TITLE,$NOTE,$DATE,$LINK){

    $SQLString="SELECT Dingoid FROM rahul_tbl_users";
    switch ($DingoID){
        case "AllUsers":
            break;
        case "AdminUsers":
            $SQLString.=" WHERE Usertype='Admin'";
            break;
        default:
            $SQLString.=" WHERE Dingoid='".$DingoID."'";
            break;
    }
    $Ergebnis=mysql_query ($SQLString);
    $Datensatz=mysql_fetch_array($Ergebnis);
    if ($Datensatz){
        while ($Datensatz){
            $DingoID=$Datensatz["Dingoid"];

            $SQLString="INSERT INTO TblNotifications (DingoID,Title,Note,Date,Link) VALUES('".$DingoID."','".$TITLE."','".$NOTE."','".$DATE."','".$LINK."')";
            $Ergebnis3=mysql_query ($SQLString) or die("IDD-Feeds: Feed nicht eingetragen");
            //echo $SQLString;
            //echo $Ergebnis3;
            //echo ("Hier sind wir in der Function 'NewFeed'");
            $xml = new DOMDocument('1.0', 'UTF-8');
            $xml->formatOutput = true;
            //echo "Vor Create Element";
            $roo = $xml->createElement('rss');
            // "Nach Create Element";
            $roo->setAttribute('version', '2.0');
            $xml->appendChild($roo);

            $cha = $xml->createElement('channel');
            $roo->appendChild($cha); 

            $hea = $xml->createElement('title',
                utf8_encode('IDD-RSS'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('description',
                utf8_encode('IDD Request Feeds'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('language',
                utf8_encode('en'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('link',
                htmlentities('http://intranet.siemens-enterprise.com/sitecore/content/Home/Intranet/organization/sales/global-sales-operations/global-bid-management/international-cross-border-group/international-deal-desk'));
            $cha->appendChild($hea);

            $hea = $xml->createElement('lastBuildDate',
                utf8_encode(date("D, j M Y H:i:s ").'CET'));
            $cha->appendChild($hea);


            $SQLString2="SELECT * FROM TblNotifications WHERE DingoID='".$DingoID."' ORDER BY Date";
            //echo $SQLString;
            $Ergebnis2=mysql_query ($SQLString2) or die("IDD-Feeds: Keine Daten aus dem Notification-File");
            $Datensatz2=mysql_fetch_array($Ergebnis2);
            if ($Datensatz2){
                while ($Datensatz2){
                    $itm = $xml->createElement('item');
                    $cha->appendChild($itm);
                    $dat = $xml->createElement('title',utf8_encode($Datensatz2["Title"]));
                    $itm->appendChild($dat);
                    $dat = $xml->createElement('description',utf8_encode($Datensatz2["Note"]));
                    $itm->appendChild($dat);   
                    $dat = $xml->createElement('link',htmlentities($Datensatz2["Link"]));
                    $itm->appendChild($dat);
                    $dat = $xml->createElement('pubDate',utf8_encode($Datensatz2["Date"]));
                    $itm->appendChild($dat);
                    $dat = $xml->createElement('guid',utf8_encode($Datensatz2["FeedID"]));
                    $itm->appendChild($dat);
                    $Datensatz2=mysql_fetch_array($Ergebnis2);
                }
            }
            //echo "Jetzt wird dann das xml-File geschrieben mit: ".$DingoID;
            $xml->save('../feeds/'.$DingoID.'.rss');
            $Datensatz=mysql_fetch_array($Ergebnis);
        }
    }
}
?>
</body>

</html>

And I want to link this php code to the RSS links so that RSS feeds work. Here are my links for the RSS feeds:

<?php
if(!isset($_SESSION))
{

session_start();
$dingo=$_SESSION['dingo'];

}
?>

<ul>
All feeds are populated even if the Email has been deactivated.Your feeds are:
<li>
 <label for="g_feed_browser"><a style="color:black; text-decoration:none" href="http://rss.groups.yahoo.com/group/rss-board/<?php echo $dingo; ?>"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe to your personal/group HTTP feed via browser: </a></label>
</li> <br>
<li>
 <label for="g_feed_outlook"><a style="color:black; text-decoration:none" href="feed://rss.groups.yahoo.com/group/rss-board/rss"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe to your personal/group feed using Outlook : </a></label>
</li><br>
IDD General rss feeds are as follows:<br>
<li>
 <label for="idd_feed_browser"><a style="color:black; text-decoration:none" href="http://feeds.rssboard.org/rssboard"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe IDD HTTP feed via browser: </a></label>
</li><br>
<li>
 <label for="idd_feed_outlook"><a style="color:black; text-decoration:none" href="http://feeds.rssboard.org/rssboard"
 target="_blank"><img src="rss1.gif" width="17" height="17" border="0" >Subscribe to IDD feed using Outlook: </a></label>
</li>
</ul>

Step 1:

You'll have to create a php file, lets say generate.php that accepts a GET param feedId :

// grab feed id from $_GET
if(!isset($_GET['feedId'])) {
    header('HTTP/1.1 400 Bad Request');
    echo 'You have been missing the feed id';
    die();
}
$feedId = $_GET['feedId'];

// now generate the *feed* depending on feed id
switch ($feedId) {
    case 'feed1' :
        header('Content-Type: application/rss');
        // generate feed here
        echo 'feed1';
        break;

    case 'feed2' :
        header('Content-Type: application/rss');
        // generate feed here
        echo 'feed1';

    default :
        header('HTTP/1.1 404 Not found');
        echo 'The document you were searching for was not found';
        die();
}

You can use a link like:

<a href="http://server/generate.php?feedId=feed1">feed 1</a>
<a href="http://server/generate.php?feedId=feed2">feed 2</a>

In a second, optional, step you could use a rewrite rule in your .htaccess file which can look like this:

RewriteEngine On   
RewriteRule ^feeds/(.*)\.rss\/?$ generate.php?feedId=$1

Now your links could look like:

<a href="http://server/feeds/feed1.rss">feed 1</a>
<a href="http://server/feeds/feed2.rss">feed 2</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM