Pagina 1 di 2 12 UltimoUltimo
Visualizzazione risultati 1 fino 30 di 50

Discussione: [MySQL - WordPress] Aggiunta di backslash automatiche

  1. #1
    Guest

    Unhappy [MySQL - WordPress] Aggiunta di backslash automatiche

    Negli ultimi commenti del mio blog si trovano delle orribili backslash prima degli apostrofi e dei segni di quote.
    Ho cercato informazioni al riguardo di quest'errore ed ho trovato due topic nel forum di supporto di WordPress:

    Se ho capito bene l'errore è legato agli aggiornamenti del database mysql...
    Avete notizie al riguardo o si tratta di un bug di WordPress non gestibile da Altervista?

  2. #2
    Guest

    Predefinito

    Beh, WordPress l'ho installato anche io tempo fa e mi sembrava funzionasse bene, quindi temo sia un bug 'nuovo', comunque facilmente risolvibile con stripslashes() (ma suppongo tu lo sappia già! )

  3. #3
    Guest

    Predefinito

    no.. non lo so.. appunto x qst ho scritto qui eheh
    che cosa dovrei fare?

  4. #4
    Guest

    Predefinito

    Allora: la funzione stripslashes($stringa) rimuove i backslash in eccesso (quelli messi automaticamente dal PHP) dalla stringa specificata. Metti quella funzione prima dell'inserimento dei dati nel database e/o prima dell'output e dovresti risolvere!

    Edit: Ricordandoti come Moderatore pensavo lo sapessi già... Mi dimentico sempre che anche i Moderatori sono esseri umani!!!
    Ultima modifica di tryphpnuke : 24-06-2006 alle ore 20.57.01

  5. #5
    Guest

    Predefinito

    c'è solo un problema, già tempo fa avevo provato ad inserire codice Php nei post ma mi vengono automaticamente cancellati da WordPress...

  6. #6
    Guest

    Predefinito

    No... quella funzione la devi inserire dentro al codice PHP di WordPress nella pagina che inserisce i commenti e/o nella pagina che te li fa visualizzare in modo da rimuovere i backslash in eccesso!

  7. #7
    Guest

    Predefinito

    Citazione Originalmente inviato da tryphpnuke
    Ricordandoti come Moderatore pensavo lo sapessi già... Mi dimentico sempre che anche i Moderatori sono esseri umani!!!
    Non sono più Moderatore...

    Devo mettere stripslashes($stringa) ma che nome metto al posto di stringa?

  8. #8
    Guest

    Predefinito

    La variabile che contiene il testo del post! Se vuoi essere più 'sicuro' fai una cosa del genere anche per tutti gli altri campi che contengono un qualsiasi testo (nome, oggetto, ...)!

    [ot]Per questo ho scritto 'Ricordandoti'... [/ot]

  9. #9
    Guest

    Predefinito

    m sa che è un casino... in quale file dovrei effettuare l'aggiunta?

  10. #10
    Guest

    Predefinito

    Non lo so... è un bel po' che non uso WordPress...
    Comunque prova a vedere se esiste qualche file chiamato post_comment.php o qualcosa di simile... Altrimenti modifichi solo la pagina che visualizza i commenti!

  11. #11
    Guest

    Predefinito

    ....... non funziona

  12. #12
    Guest

    Predefinito

    Dove hai inserito il codice?

  13. #13
    Guest

    Predefinito

    nella pagina comments.php della templates in uso al momento.
    E' molto probabile che non sia collocato nel posto giusto o che si tratti di una soluzione non valida

  14. #14
    Guest

    Predefinito

    Allora, ho visto un po' il tuo blog e, sbirciando tra l'HTML, spero di avere capito bene che devi andare a correggere questa pagina: /blog/wp-comments-post.php (quella che mette i dati nel database)
    Fammi sapere...
    Ultima modifica di tryphpnuke : 24-06-2006 alle ore 21.49.19 Motivo: Errore di ortografia!

  15. #15
    Guest

    Predefinito

    ho provato ad inserire stripslashes($_POST['comment']); o stripslashes($comment_content); ma non si risolve

  16. #16
    Guest

    Predefinito

    Uhm... la funzione è corretta... (http://it2.php.net/stripslashes) Puoi postare il codice della pagina?

  17. #17
    Guest

    Predefinito

    Codice della pagina wp-comments-post.php
    Codice:
    <?php
    require( dirname(__FILE__) . '/wp-config.php' );
    
    nocache_headers();
    
    $comment_post_ID = (int) $_POST['comment_post_ID'];
    
    $status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");
    
    if ( empty($status->comment_status) ) {
    	do_action('comment_id_not_found', $comment_post_ID);
    	exit;
    } elseif ( 'closed' ==  $status->comment_status ) {
    	do_action('comment_closed', $comment_post_ID);
    	die( __('Sorry, comments are closed for this item.') );
    } elseif ( 'draft' == $status->post_status ) {
    	do_action('comment_on_draft', $comment_post_ID);
    	exit;
    }
    
    $comment_author       = trim($_POST['author']);
    $comment_author_email = trim($_POST['email']);
    $comment_author_url   = trim($_POST['url']);
    $comment_content      = trim($_POST['comment']);
    
    stripslashes($_POST['comment']); 
    
    // If the user is logged in
    $user = wp_get_current_user();
    if ( $user->ID ) :
    	$comment_author       = $wpdb->escape($user->display_name);
    	$comment_author_email = $wpdb->escape($user->user_email);
    	$comment_author_url   = $wpdb->escape($user->user_url);
    else :
    	if ( get_option('comment_registration') )
    		die( __('Sorry, you must be logged in to post a comment.') );
    endif;
    
    $comment_type = '';
    
    if ( get_settings('require_name_email') && !$user->ID ) {
    	if ( 6 > strlen($comment_author_email) || '' == $comment_author )
    		die( __('Error: please fill the required fields (name, email).') );
    	elseif ( !is_email($comment_author_email))
    		die( __('Error: please enter a valid email address.') );
    }
    
    if ( '' == $comment_content )
    	die( __('Error: please type a comment.') );
    
    $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
    
    $comment_id = wp_new_comment( $commentdata );
    
    if ( !$user->ID ) :
    	$comment = get_comment($comment_id);
    	setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    	setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    	setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    endif;
    
    $location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to']; 
    
    wp_redirect( $location );
    
    ?>
    Ultima modifica di Extralife : 24-06-2006 alle ore 22.13.08

  18. #18
    L'avatar di mythologia
    mythologia non è connesso Moderatore
    Data registrazione
    05-01-2004
    Messaggi
    2,614

    Predefinito

    Codice PHP:
    <?php
    require( dirname(__FILE__) . '/wp-config.php' );

    nocache_headers();

    $comment_post_ID = (int) $_POST['comment_post_ID'];

    $status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");

    if ( empty(
    $status->comment_status) ) {
    do_action('comment_id_not_found', $comment_post_ID);
    exit;
    } elseif (
    'closed' == $status->comment_status ) {
    do_action('comment_closed', $comment_post_ID);
    die(
    __('Sorry, comments are closed for this item.') );
    } elseif (
    'draft' == $status->post_status ) {
    do_action('comment_on_draft', $comment_post_ID);
    exit;
    }

    $_POST['comment'] = stripslashes($_POST['comment']);

    $comment_author = trim($_POST['author']);
    $comment_author_email = trim($_POST['email']);
    $comment_author_url = trim($_POST['url']);
    $comment_content = trim($_POST['comment']);

    // If the user is logged in
    $user = wp_get_current_user();
    if (
    $user->ID ) :
    $comment_author = $wpdb->escape($user->display_name);
    $comment_author_email = $wpdb->escape($user->user_email);
    $comment_author_url = $wpdb->escape($user->user_url);
    else :
    if (
    get_option('comment_registration') )
    die(
    __('Sorry, you must be logged in to post a comment.') );
    endif;

    $comment_type = '';

    if (
    get_settings('require_name_email') && !$user->ID ) {
    if (
    6 > strlen($comment_author_email) || '' == $comment_author )
    die(
    __('Error: please fill the required fields (name, email).') );
    elseif ( !
    is_email($comment_author_email))
    die(
    __('Error: please enter a valid email address.') );
    }

    if (
    '' == $comment_content )
    die(
    __('Error: please type a comment.') );

    $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');

    $comment_id = wp_new_comment( $commentdata );

    if ( !
    $user->ID ) :
    $comment = get_comment($comment_id);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    endif;

    $location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'];

    wp_redirect( $location );

    ?>
    Così dovrebbe essere OK
    Ultima modifica di mythologia : 24-06-2006 alle ore 22.30.38

  19. #19
    Guest

    Predefinito

    A parte che non vedo nessun 'INSERT INTO' come query, io fossi in te riproverei così:
    Codice PHP:
    <?php
    require( dirname(__FILE__) . '/wp-config.php' );

    nocache_headers();

    $comment_post_ID = (int) $_POST['comment_post_ID'];

    $status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");

    if ( empty(
    $status->comment_status) ) {
    do_action('comment_id_not_found', $comment_post_ID);
    exit;
    } elseif (
    'closed' == $status->comment_status ) {
    do_action('comment_closed', $comment_post_ID);
    die(
    __('Sorry, comments are closed for this item.') );
    } elseif (
    'draft' == $status->post_status ) {
    do_action('comment_on_draft', $comment_post_ID);
    exit;
    }

    $_POST['comment'] = stripslashes($_POST['comment']);
    $comment_author = trim($_POST['author']);
    $comment_author_email = trim($_POST['email']);
    $comment_author_url = trim($_POST['url']);
    $comment_content = trim($_POST['comment']);

    // If the user is logged in
    $user = wp_get_current_user();
    if (
    $user->ID ) :
    $comment_author = $wpdb->escape($user->display_name);
    $comment_author_email = $wpdb->escape($user->user_email);
    $comment_author_url = $wpdb->escape($user->user_url);
    else :
    if (
    get_option('comment_registration') )
    die(
    __('Sorry, you must be logged in to post a comment.') );
    endif;

    $comment_type = '';

    if (
    get_settings('require_name_email') && !$user->ID ) {
    if (
    6 > strlen($comment_author_email) || '' == $comment_author )
    die(
    __('Error: please fill the required fields (name, email).') );
    elseif ( !
    is_email($comment_author_email))
    die(
    __('Error: please enter a valid email address.') );
    }

    if (
    '' == $comment_content )
    die(
    __('Error: please type a comment.') );

    $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');

    $comment_id = wp_new_comment( $commentdata );

    if ( !
    $user->ID ) :
    $comment = get_comment($comment_id);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    endif;

    $location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'];

    wp_redirect( $location );

    ?>
    Edit: mythologia, lo stripslashes lo deve mettere PRIMA di avere creato la variabile $comment_content, perché dopo non serve a niente!
    Ultima modifica di tryphpnuke : 24-06-2006 alle ore 22.18.28

  20. #20
    Guest

    Predefinito

    purtroppo è come prima

  21. #21
    L'avatar di mythologia
    mythologia non è connesso Moderatore
    Data registrazione
    05-01-2004
    Messaggi
    2,614

    Predefinito

    azz, è vero... piccola distrazione

    Comunque temo che non sia questoil file

  22. #22
    Guest

    Predefinito

    Riproviamo ancora:
    Codice PHP:
    <?php
    require( dirname(__FILE__) . '/wp-config.php' );

    nocache_headers();

    $comment_post_ID = (int) $_POST['comment_post_ID'];

    $status = $wpdb->get_row("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");

    if ( empty(
    $status->comment_status) ) {
    do_action('comment_id_not_found', $comment_post_ID);
    exit;
    } elseif (
    'closed' == $status->comment_status ) {
    do_action('comment_closed', $comment_post_ID);
    die(
    __('Sorry, comments are closed for this item.') );
    } elseif (
    'draft' == $status->post_status ) {
    do_action('comment_on_draft', $comment_post_ID);
    exit;
    }

    $comment_author = trim($_POST['author']);
    $comment_author_email = trim($_POST['email']);
    $comment_author_url = trim($_POST['url']);
    $comment_content = stripslashes(trim($_POST['comment']));

    // If the user is logged in
    $user = wp_get_current_user();
    if (
    $user->ID ) :
    $comment_author = $wpdb->escape($user->display_name);
    $comment_author_email = $wpdb->escape($user->user_email);
    $comment_author_url = $wpdb->escape($user->user_url);
    else :
    if (
    get_option('comment_registration') )
    die(
    __('Sorry, you must be logged in to post a comment.') );
    endif;

    $comment_type = '';

    if (
    get_settings('require_name_email') && !$user->ID ) {
    if (
    6 > strlen($comment_author_email) || '' == $comment_author )
    die(
    __('Error: please fill the required fields (name, email).') );
    elseif ( !
    is_email($comment_author_email))
    die(
    __('Error: please enter a valid email address.') );
    }

    if (
    '' == $comment_content )
    die(
    __('Error: please type a comment.') );

    $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');

    $comment_id = wp_new_comment( $commentdata );

    if ( !
    $user->ID ) :
    $comment = get_comment($comment_id);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
    endif;

    $location = ( empty( $_POST['redirect_to'] ) ) ? get_permalink( $comment_post_ID ) : $_POST['redirect_to'];

    wp_redirect( $location );

    ?>
    Edit: SONO UTENTE ATTIVO!!!
    Ultima modifica di tryphpnuke : 24-06-2006 alle ore 22.29.14

  23. #23
    L'avatar di mythologia
    mythologia non è connesso Moderatore
    Data registrazione
    05-01-2004
    Messaggi
    2,614

    Predefinito

    Credo che questo sia il file per inviare i COMMENTI alle news, a noi serve quello che lo porta in output

  24. #24
    Guest

    Predefinito

    sempre come prima, l'errore persiste.

  25. #25
    Guest

    Predefinito

    mythologia: va bene, ma se noi lo mettiamo nello script che invia le news preveniamo tutti gli errori nei futuri post...
    Extralife: mi sorge un dubbio: ma tu stai guardando sempre i vecchi post o stai provando a inviarne di nuovi?

    Edit: allora, il problema per i nuovi post è risolto... (http://extralife.altervista.org/blog...mbia-il-tempo/, è l'ultimo commento, che va eliminato) Adesso ci possiamo concentrare su come riolvere il problema per i vecchi post!
    Ultima modifica di tryphpnuke : 24-06-2006 alle ore 22.40.24

  26. #26
    Guest

    Predefinito

    io sto provando a correggere i post che contengono l'errore: nel menù Manage seleziono Comments e poi Edit e da lì cancello le backslash ma dopo aver salvato tornano in automatico

  27. #27
    Guest

    Predefinito

    Dovresti applicare più o meno le stesse modifiche al file che permette all'admin di modificare i commenti!

  28. #28
    L'avatar di mythologia
    mythologia non è connesso Moderatore
    Data registrazione
    05-01-2004
    Messaggi
    2,614

    Predefinito

    si, perchè come detto, bisogna lavorare sul file di output.

    tryphpnuke: sospettavo che i problemi ci fossero con i vecchi

  29. #29
    Guest

    Predefinito

    aspetta un attimo, io ho tolto il codice che avevamo messo ed adesso sembra che il problema non c sia più.. come è possibile che per gli altri due commenti allora le backslash non vogliano andarsene??

  30. #30
    Guest

    Predefinito

    mythologia: Lavorare con l'output temo che sia difficile perché crea una nuova directory per ogni nuovo post nel blog...

Pagina 1 di 2 12 UltimoUltimo

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •