Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it L'avatar di ghety
    Registrato dal
    Sep 2002
    Messaggi
    115

    [PHP-XML-RSS & Sicurezza] Meglio dinamico o statico

    Ciao a tutti
    spero di esporre il mio dubbio con chiarezza.
    Ho intenzione di costruire un xml/rss e fin qui
    nessun problema.
    I dubbi mi vengono dopo aver letto un ottimo articolo su
    html.it (http://webnews.html.it/focus/387.htm) quando
    si parla di sicurezza di questi xml/rss che possono essere
    soggetti ad attacchi DDOS.
    Per fortuna però ci sono alcuni rimedi (come dice l'articolo)
    tra cui l'uso del "Conditional GET".

    A questo punto la domanda.
    Conviene far generare dinamicamente xml/rss da un file
    rss.php (ad esempio) dove preleva i dati da un db e riuscendo anche
    a gestire gli header (Last-Modified; Etag; If-Modified-Since; If-None-Match) per risolvere il problema
    di sicurezza ma con un carico del db maggiore
    oppure
    inviare al server un file rss.xml statico
    ma a questo punto non saprei come gestire questi header?

    Spero di essere stato chiaro (mmmmmmh)

    Grazie
    # 340637

  2. #2
    Utente di HTML.it L'avatar di ghety
    Registrato dal
    Sep 2002
    Messaggi
    115
    un uppino
    # 340637

  3. #3
    Utente di HTML.it L'avatar di ghety
    Registrato dal
    Sep 2002
    Messaggi
    115
    A questo punto ho un'altro dubbio
    Interessa a pochi
    o in pochi conoscono queste caratteristiche
    o non ho chiarito bene il problema
    o non io chiaro il problema

    Aspetto ancora fiducioso

    Grazie
    # 340637

  4. #4
    Utente di HTML.it L'avatar di ghety
    Registrato dal
    Sep 2002
    Messaggi
    115
    Riprende questa discussione.
    Girovagando ho trovato una funzione
    per gestire il cd "Conditional GET"
    per evitare eventueli, voluti o non voluti,
    attacchi DOS.

    Questo è il codice, è gradito qualsiasi intervento

    Grazie

    Codice PHP:
    <?
    header
    ("Content-Type: text/xml;charset=ISO-8859-1");
    /*
        CONNESSIONE AL DB
    */
    $connessione mysql_connect ('host''user''psw');
    $dbase mysql_select_db ('DB'$connessione) ;
    $query1 " SELECT id,titolo,testo,data FROM tabella ORDER BY data DESC    LIMIT 10";        
    $result1 mysql_query($query1);

    // prima parte dell'xml
    $stringa '<?xml version="1.0" encoding="ISO-8859-1"?>
    <rss version="0.92">
       <channel>
          <title>Tuo sito</title>
          <link>[url]http://www.sito.it[/url]</link>
          <description>Le ultime del sito</description>
          <language>it</language>
          <image>
            <title>Tuo sito</title>
            <url>[url]http://www.sito.it/images/sito.gif[/url]</url>
            <link>[url]http://www.sito.it/[/url]</link>
            <width>88</width>
            <height>30</height>
         </image>
    '
    ;

    // tutti gli altri item
    $a 
    while ( 
    $row mysql_fetch_assoc($result1) ){
        if (
    $a=="0") { 
            
    $prima_data $row["data"]; // mi memorizzo la data più recente
            
    $a++;
        }
       
    $title cleanText($row["titolo"]);
       
    $link cleanText("http://www.sito.it/visualizza.php?id=".$row["id"]);
       
    $description cleanText($row["testo"]);

    $stringa .= "<item>
             <title>
    $title</title>
             <link>
             
    $link</link>
             <description>
    $description</description>
          </item>
    "
    ;
    }

    // chiude il file xml
    $stringa .= "
       </channel>
    </rss>
    "
    ;

    mysql_free_result($result1);

    doConditionalGet($prima_data);

    print 
    $stringa;

    /*
        FUNZIONI
    */
    // testo HTML compatibile XML
    function cleanText($intext) {
        return 
    htmlspecialchars(stripslashes($intext));
    }

    function 
    doConditionalGet($timestamp) {
        
    // A PHP implementation of conditional get, see 
        //   [url]http://fishbowl.pastiche.org/archives/001132.html[/url]
        
    $last_modified substr(date('r'$timestamp), 0, -5).'GMT';
        
    $etag '"'.md5($last_modified).'"';
        
    // Send the headers
        
    header("Last-Modified: $last_modified");
        
    header("ETag: $etag");
        
    // See if the client has provided the required headers
        
    $if_modified_since = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ?
            
    stripslashes($_SERVER['HTTP_IF_MODIFIED_SINCE']) :
            
    false;
        
    $if_none_match = isset($_SERVER['HTTP_IF_NONE_MATCH']) ?
            
    stripslashes($_SERVER['HTTP_IF_NONE_MATCH']) : 
            
    false;
        if (!
    $if_modified_since && !$if_none_match) {
            return;
        }
        
    // At least one of the headers is there - check them
        
    if ($if_none_match && $if_none_match != $etag) {
            return; 
    // etag is there but doesn't match
        
    }
        if (
    $if_modified_since && $if_modified_since != $last_modified) {
            return; 
    // if-modified-since is there but doesn't match
        
    }
        
        
    // Nothing has changed since their last request - serve a 304 and exit
        
    header('HTTP/1.0 304 Not Modified');
        exit;
    }
    ?>
    # 340637

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.