Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Il controllo captcha funziona in locale ma non sul web

    Salve ragazzi,

    questa cosa che sto per raccontarvi è incredibile. Probabilmente ho commesso qualche errore ma è da questa mattina che non riesco a capire cosa ho sbagliato. Ho creato una pagina contenente un form per effettuare prenotazioni online. Questo form prevede anche l'implementazione di uno script per generare i captcha. La cosa incredibile è che in locale (easyphp) funziona tutto ma quando faccio l'upload sul web non mi fa il controllo dell'immagine captcha. Vi posto il codice:

    Questa è la pagina form.php che contiene il form

    Codice PHP:
    <?php
    session_start
    ();
    ?>
    <?php 
    include('template/doctype.php');?>
    <html>
    <?php include('template/head_form.php');?>
    <body>
    <div id="content">
    <?php
    if (isset($_SESSION['errore']) and $_SESSION['errore']!='no_errors') {        
        echo 
    '<div class="errori">[b]Si sono verificati i seguenti errori:[/b]<ul>';
        if (
    $_SESSION['errore']['element_0']==true) {
            echo 
    '[*]Non hai inserito il tuo NOME o il nome è più corto di 3 caratteri.';
        }
        if (
    $_SESSION['errore']['element_1']==true) {
            echo 
    '[*]Non hai inserito il tuo COGNOME o il cognome è più corto di 3 caratteri.';
        }
        if (
    $_SESSION['errore']['element_2']==true) {
            echo 
    '[*]Non hai inserito il tuo indirizzo EMAIL o non è un indirizzo email valido.';
        }
        if (
    $_SESSION['errore']['element_8']==true) {
            echo 
    '[*]La data di CHECK-IN inserita non è corretta.';
        }
        if (
    $_SESSION['errore']['element_9']==true) {
            echo 
    '[*]La data di CHECK-OUT inserita non è corretta.';
        }
        if (
    $_SESSION['errore']['element_10']==true) {
            echo 
    '[*]Non hai inserito la RICHIESTA.';
        }
        if (
    $_SESSION['errore']['element_11']==true) {
            echo 
    '[*]Devi accettare i TERMINI PER LA PRIVACY.';
        }
        if (
    $_SESSION['errore']['element_12']==true) {
            echo 
    '[*]Il TESTO inserito non è corretto.';
        }
        else {
            if (
    $_SESSION['errore']['server']==true) {
                echo 
    '[*]La mail non è stata inviata a causa di un PROBLEMA DEL SERVER, riprova più tardi.';
            }
        }
       echo 
    '[/list]</div>';
    }
    else {
        if (isset(
    $_SESSION['errore']) and $_SESSION['errore']=='no_errors') {
            echo 
    '<div class="send_ok">La mail è stata inviata correttamente.</div>';
        }
    }
    ?>
    <h2>Richiesta prenotazione</h2>


    <form method="post" action="script/send.php">
    <table>            
        <tr>
            <th>Nome <small style="color:red;">*</small></th>
            <th><input id="element_0" name="element_0" value="<?php echo $_SESSION['dati']['element_0']; ?>" class="input" size="25" type="text"></th>
        </tr>
        <tr>
            <th>Cognome <small style="color:red;">*</small></th>
            <th><input id="element_1" name="element_1" value="<?php echo $_SESSION['dati']['element_1']; ?>" class="input" size="25" type="text"></th>
        </tr>
        <tr>
            <th>Email <small style="color:red;">*</small></th>
            <th><input id="element_2" name="element_2" value="<?php echo $_SESSION['dati']['element_2']; ?>" class="input" size="25" type="text"></th>
        </tr>
        <tr>
            <th>Numero adulti <small style="color:red;">*</small></th>
            <th>
                <select id="element_4" name="element_4">
                    <option value="1" selected="selected">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                </select>
            </th>
        </tr>
        <tr>
            <th>Numero bambini <small style="color:red;">*</small>
    <div><small style="color:red;">Bambini fino a 13 anni</small></div></th>
            <th>
                <select id="element_5" name="element_5">
                    <option value="0"selected="selected">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                </select>
            </th>
        </tr>
        <tr>
            <th>Appartamento <span style="color:red;">[size="1"]*[/size]</span></th>
            <th>
                <select id="element_6" name="element_6">
                    <option value="Sole"selected="selected">Sole</option>
                    <option value="Luna">Luna</option>
                    <option value="Gioia">Gioia</option>
                    <option value="Elsa">Elsa</option>
                    <option value="Marilena">Marilena</option>
                    <option value="Camera Rosa">Camera Rosa</option>
                </select>
            </th>
        </tr>
        <tr>
            <th>Modalit&agrave; servizio <small style="color:red;">*</small></th>
            <th>
                <select id="element_7" name="element_7">
                    <option value="Solo pernottamento" selected="selected">Solo pernottamento</option>
                    <option value="Bed&amp;Breakfast">Bed&amp;Breakfast</option>
                    <option value="Mezza pensione">Mezza pensione</option>
                    <option value="Pensione completa">Pensione completa</option>
                </select>
            </th>
        </tr>
        <tr>
            <th>Data di Check-IN <small style="color:red;">*</small>
    <div><small style="color:red;">GG/MM/AAAA</small></div></th>
            <th><input id="element_8" name="element_8" value="<?php echo $_SESSION['dati']['element_8']; ?>" class="input" size="25" type="text">[img]../../obj/calendario.png[/img]</th>
        </tr>
        <tr>
            <th>Data di Check-OUT <small style="color:red;">*</small>
    <div><small style="color:red;">GG/MM/AAAA</small></div></th>
            <th><input id="element_9" name="element_9" value="<?php echo $_SESSION['dati']['element_9']; ?>" class="input" size="25" type="text">[img]../../obj/calendario.png[/img]</th>
        </tr>
        <tr valign="top">
            <th>Richiesta <small style="color:red;">*</small></th>
            <th><textarea id="element_10" name="element_10" cols="23" rows="10"><?php echo $_SESSION['dati']['element_10']; ?></textarea></th>
        </tr>
        <tr>
            <th>Accetta i termini <small style="color:red;">*</small></th>
            <th>
                <div><input type="checkbox" id="element_11" name="element_11[]" value="Accetto">Accetto [[url="javascript:void(0);"]?[/url]]</div>
            </th>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr>
            <th colspan="2">Perfavore inserisci il testo dell'immagine</th>
        </tr>
        <tr>
            <td></td>
        </tr>
        <tr valign="top">
            <td>[img]script/captcha.php[/img]</td>
            <th>
                <div><input id="element_12" name="element_12" size="25" type="text" class="input">
    [[url="javascript:void(0);"]Cambia Immagine[/url]]
                </div>
            </th>
        </tr>            
        <tr>
            <td></td>
        </tr>
        <tr>
            <td colspan="2"><input name="element_counts" value="11" type="hidden"><input value="Invia la Richiesta" type="submit"></td>
        </tr>
    </table>
    </form>
    <div class="clearer">

    </p></div>
    </div>
    <?php include('template/footer.php');?>
    </div>
    </body>
    </html>
    Questa è la pagina send.php

    Codice PHP:
    <?php
    session_start
    ();

    if (isset(
    $_POST['element_0']) and isset($_POST['element_1']) and isset($_POST['element_2']) and isset($_POST['element_8']) and isset($_POST['element_9']) and isset($_POST['element_10']) and isset($_POST['element_12'])) {

       
    //filtro i dati inviati

       
    $nome=htmlentities(trim($_POST['element_0']),ENT_QUOTES);
       
    $cognome=htmlentities(trim($_POST['element_1']),ENT_QUOTES);
       
    $email_mittente=htmlentities(trim($_POST['element_2']),ENT_QUOTES);
       
    $adulti=htmlentities(trim($_POST['element_4']),ENT_QUOTES);
       
    $bambini=htmlentities(trim($_POST['element_5']),ENT_QUOTES);
       
    $appartamento=htmlentities(trim($_POST['element_6']),ENT_QUOTES);
       
    $modalita=htmlentities(trim($_POST['element_7']),ENT_QUOTES);
       
    $in=htmlentities(trim($_POST['element_8']),ENT_QUOTES);
       
    $out=htmlentities(trim($_POST['element_9']),ENT_QUOTES);
       
    $richiesta=htmlentities(trim($_POST['element_10']),ENT_QUOTES);
       
    $accetta = isset($_POST["element_11"]) ? $_POST["element_11"] : '0';
       
    $captcha=htmlentities(trim($_POST['element_12']),ENT_QUOTES);
       
    $presenza_errori=false;

       
    //blocco di controllo degli errori

       
    if (strlen($nome)<3) {
          
    $_SESSION['errore']['element_0']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_0']=false;
       }
       
       if (
    strlen($cognome)<3) {
          
    $_SESSION['errore']['element_1']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_1']=false;
       }
       
       if(!
    preg_match'/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/'$email_mittente)) {
          
    $_SESSION['errore']['element_2']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_2']=false;
       }
       
       if(!
    preg_match('/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}/'$in)) {
          
    $_SESSION['errore']['element_8']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_8']=false;
       }
       
       if(!
    preg_match('/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}/'$out)) {
          
    $_SESSION['errore']['element_9']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_9']=false;
       }
       
       if (
    strlen($richiesta)<5) {
          
    $_SESSION['errore']['element_10']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_10']=false;
       }
       
       if (
    $accetta == 0) {
          
    $_SESSION['errore']['element_11']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_11']=false;
       }
       
       if (
    $accetta == 0) {
          
    $_SESSION['errore']['element_11']=true;
          
    $presenza_errori=true;
       }
       else {
          
    $_SESSION['errore']['element_11']=false;
       }
       
        if (
    $captcha == $_SESSION['captcha']) {
            
    $_SESSION['errore']['element_12']=false;        
        }
        else {
            
    $_SESSION['errore']['element_12']=true;
            
    $presenza_errori=true;
        }
       
       
       
    //blocco di invio dell'email

        
    if ($presenza_errori==false) {
        
    $email_destinatario='info@miamail.com';
        
    $mail_body="

    <font color=#000000>Adulti: 
    $adulti</font></p>
        

    <font color=#000000>Bambini: 
    $bambini</font></p>
        

    <font color=#000000>Appartamento: 
    $appartamento</font></p>
        

    <font color=#000000>Data-in: 
    $in</font></p>
        

    <font color=#000000>Data-out: 
    $out</font></p>
        

    <font color=#000000>Messaggio: 
    $richiesta</font></p>";
        
    $oggetto_mail="Email da $nome $cognome";
        
    $headers="To: Io <$email_destinatario>" "\r\n";
        
    $headers.="From: $nome $cognome <$email_mittente>" "\r\n";

            if (
    mail($email_destinatario$oggetto_mail$mail_body$headers)) {
            
    $_SESSION['errore']='no_errors';
            
    header('Location: ../form.php');
            }
            else {
                
    $_SESSION['errore']['server']=true;
                
    header('Location: ../form.php');
            }
        }
        else {
            
    $_SESSION['dati']=$_POST;
            
    header('Location: ../form.php');
        }
    }
    ?>
    Questa invece è la pagina che genera le immagini captcha

    Codice PHP:
    <?php
    session_start
    ();
    //Iniziamo col primo passo:
    //1.
    header ("Content-type: image/png");

    $x 170;
    $y 75;
    $code '';
    $chars explode(' ''a b c d e f g h i j k l m n o p q r s t u v w x y z');

    for(
    $i 0$i 5$i++, shuffle($chars))
        
    $code .= $chars[0];
    $space $x / (strlen($code)+1);

    $img imagecreatetruecolor($x,$y);

    $bg imagecolorallocate($img,255,255,255);
    $border imagecolorallocate($img,0,0,0);
    $colors[] = imagecolorallocate($img,128,64,192);
    $colors[] = imagecolorallocate($img,192,64,128);
    $colors[] = imagecolorallocate($img,108,192,64);

    imagefilledrectangle($img,1,1,$x-2,$y-2,$bg);
    imagerectangle($img,0,0,$x-1,$y-2,$border);

    for (
    $i=0$istrlen $code ); $i++)
    {
    $color $colors[$i count($colors)];
    imagettftext($img,28+rand(0,8),-20+rand(0,40),($i+0.3)*$space,50+rand(0,10),$color,'riverave.ttf',$code{$i});
    }

    for(
    $i=0;$i<400;$i++)
    {
    $x1 rand(3,$x-3);
    $y1 rand(3,$y-3);
    $x2 $x1-2-rand(0,8);
    $y2 $y1-2-rand(0,8);
    imageline($img,$x1,$y1,$x2,$y2,$colors[rand(0,count($colors)-1)]);
    }

    imagepng($img);
    $_SESSION['captcha'] = $code;
    ?>
    Quando sbaglio ad inserire i campi mi da errore ad eccezione del campo captcha. In pratica non fa questo if:

    Codice PHP:
    if ($_SESSION['errore']['element_12']==true) {
            echo 
    '[*]Il TESTO inserito non è corretto.';
        } 
    "Il TESTO inserito non è corretto" lo scrive solo in locale ma non in rete

    Non so più dove sbattere la testa.......

    La pagina del form è questa: http://www.marilenalacasella.com/pagine/ita/form.php
    Come noterete se premete il pulsante "Invia la Richiesta" scrive tutti gli errori meno l'ultimo "Il TESTO inserito non è corretto".

    GRAZIE A TUTTI

  2. #2
    Utente di HTML.it L'avatar di skjobax
    Registrato dal
    Jan 2010
    Messaggi
    569
    Hai provato a cambiare di posizione l'if o mettendolo in una funzione appropriata?

  3. #3
    Ora tutto funziona. Puoi vedere il risultato qui:

    http://www.marilenalacasella.com/pagine/ita/form.php

    Ciao e grazie

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.