Results 1 to 1 of 1

Thread: Cum sa implementezi RSS pe website-ul tau

  1. #1
    Uber Mood johnake's Avatar
    Join Date
    Oct 2007
    Location
    Cum dai coltu', pe dreapta
    Posts
    4,877
    Blog Entries
    4

    Default Cum sa implementezi RSS pe website-ul tau

    Acest tutorial pleaca de la premisa ca sit'ul dumneavoastra este unul dinamic (PHP+MYSQL).



    1. Faci un fisier php rss.php cu urmatorul cod.
    rss.php:
    PHP Code:
    <?php
    header
    ("Content-type: text/xml");
    echo 
    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
    // Seteaza versiunea de rss
    echo "
    <rss version=\"2.0\"> "
    ;
    // Initializam XML'ul.
    echo "
      <channel>
        <title>SitulTau.com News Feed</title>
        <description>Cele mai noi stiri bla bla bla</description>
        <link>http://www.situltau.com/</link>"

        
    // Creeaza o conexiune la baza ta de date.
        
    require("includes/connection.php"); 
        
    // Interogheaza baza de date pentru ultimele 10 rezultate.
        
    $data mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT 10");
        while(
    $row mysql_fetch_array($data)) 
        {
            
        
    // Continuam cu inserarea celor 10 obiecte ce vor fi incluse in sectiunea <item> a xml'ului.
        
    echo "
        <item>
          <link>http://www.situltau.com/news.php?id="
    .$row[id]."</link>//news.php este un link generic... de dragul exemplului
          <guid isPermaLink=\"true\">http://www.situltau.com/news.php?id="
    .$row[id]."</guid>
          <title>"
    .$row[titlu]."</title>//.$row[titlu]. //extrage din baza de date titlul articolului/stirii
          <description><![CDATA["
    .$row[content]."]]></description>//extrage din baza de date continutul articolului 
            
        </item>"

    }
     
    echo 
    "
      </channel>
    </rss>"
    ;
    ?>
    2. In fisierul rss.php ar am observat ca el se conecteaza la o baza de date cu ajutorul unui fisier numit de noi "connection.php". Probabil va intrebati ce contine acest fisier. El contine liniile necesare conectarii la serverul de baze de date mysql si la baza de date propriu-zisa.

    connection.php:
    PHP Code:
    <?
    @mysql_connect('host_baza_de_date' 'username' 'parola') or die('Eroare-- nu ma pot conecta la server');

    @
    mysql_select_db('numebazadedate') or die('Eroare nu ma pot conecta la baza de date');
    ?>
    Dupa cum observati din rss.php[require("includes/connection.php")] fisierul connection.php rezidua in folder-ul includes din root'ul sitului.

    Modificati acest script conform nevoilor voastre si "you are ready to go"!
    "Postmodernism is a complete assault on two things: One, itís an assault on the metaphysical substrate of our culture, and I would say that the metaphysical substrate looks something like a religious substrate, so itís a direct assault on that; and the second thing itís an assault on is everything thatís been established since the enlightenment; rationality, empiricism, science.. everything; clarity of mind, dialogue, the idea of the individual, all of that"

    dr. Jordan B. Peterson

  2. The Following 2 Users Say Thank You to johnake For This Useful Post:

    iLink (04-07-2011), Stiglitz (12-29-2010)

Similar Threads

  1. Replies: 1
    Last Post: 08-19-2008, 12:34 PM
  2. RIAA website hacked by SQL injection!
    By UNLiMiTED in forum World Wide Web
    Replies: 6
    Last Post: 05-24-2008, 12:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •