Buongiorno a tutti 
Nel mio sito ho bisogno che un variabile numerica acquisita dall'invio di tre form, rimanga anche dopo il refresh della pagina. Così ho deciso di usare i cookies, ma per qualche oscuro motivo non funzionano: quando si refresha la pagina la variante $totale si standardizza su 1 invece che sul numero ottenuto dai form. Vedete qualche mio errore? Codice del form:
codice HTML:
<div id="ac_content" class="ac_content"> <h1>Oracolo del Web<span><br />Completa i campi e poi premi invio</span></h1> <form name="campo" action="frase2.php" method="post"> <div class="ac_menu"> <ul> <li> <a href="images/galassia2.jpg">Giorno</a> <div class="ac_subitem"> <span class="ac_close"></span> <h2>Giorno</h2> <ul> <li>Che giorno è oggi? Inserisci il numero qui sotto e premi invio sulla tastiera.</li> <li><br /></li> </ul> <input type="text" name="giorno" size="15" maxlength="2" onkeyup="char_consentiti(this)"> </div> </li> <li> <a href="images/galassia3.jpg">Mese</a> <div class="ac_subitem"> <span class="ac_close"></span> <h2>Mese</h2> <ul> <li>In che mese siamo oggi? Inserisci il numero qui sotto e premi invio sulla tastiera.</li> <li><br /></li> </ul> <input type="text" name="mese" size="15" maxlength="2" onkeyup="char_consentiti(this)"> </div> </li> <li> <a href="images/galassia4.jpg">Nome</a> <div class="ac_subitem"> <span class="ac_close"></span> <h2>Nome</h2> <ul> <li>Come ti chiami? Inserisci il tuo nome qui sotto e premi invio sulla tastiera.</li> <li><br /></li> </ul> <input type="text" name="nome" size="15" maxlength="15"> </div> </li> <li> <a href="images/galassia5.jpg">Invio</a> <div class="ac_subitem"> <span class="ac_close"></span> <h2>Invio</h2> <ul> <li><p>Premi Invia per visualizzare il responso dell'oracolo.</p></li> <li><br /></li> </ul> <input type="submit" name="Invia" value=" Invia " onclick="location.href='frase2.php'"> </div> </li> </ul> </div> </form> </div>
Cookies e codice PHP:
Codice PHP:
<?php if (isset($_POST['giorno'])) { $giorno = htmlspecialchars($_POST['giorno']); } else if (isset($_COOKIE['giorno'])) { $giorno = $_POST['giorno']; } if (isset($_POST['mese'])) { $mese = htmlspecialchars($_POST['mese']); } else if (isset($_COOKIE['mese'])) { $mese = $_POST['mese']; } if (isset($_POST['nome'])) { $nome = htmlspecialchars($_POST['nome']); } else if (isset($_COOKIE['nome'])) { $nome = $_POST['nome']; } $lunghezzanome = strlen($nome); $numero = $giorno + $mese + $lunghezzanome; setcookie("cookie", $numero, time()+3600);?>
<?php if(isset($_COOKIE["cookie"])) { $totalee = $_COOKIE["cookie"]; } $totale = $totalee; if(!$_GET) { switch($totale) { case $totale == 0 || $totale == 10 || $totale == 20 || $totale == 30 || $totale == 40 || $totale == 50 || $totale == 60 || $totale == 70 || $totale == 80 || $totale == 90 || $totale == 100; $frasi = file('txt/frasi0.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.$indice_random.'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 1 || $totale == 11 || $totale == 21 || $totale == 31 || $totale == 41 || $totale == 51 || $totale == 61 || $totale == 71 || $totale == 81 || $totale == 91 || $totale == 101; $frasi = file('txt/frasi1.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 19).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 2 || $totale == 12 || $totale == 22 || $totale == 32 || $totale == 42 || $totale == 52 || $totale == 62 || $totale == 72 || $totale == 82 || $totale == 92 || $totale == 102; $frasi = file('txt/frasi2.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 38).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 3 || $totale == 13 || $totale == 23 || $totale == 33 || $totale == 43 || $totale == 53 || $totale == 63 || $totale == 73 || $totale == 83 || $totale == 93 || $totale == 103; $frasi = file('txt/frasi3.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 57).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 4 || $totale == 14 || $totale == 24 || $totale == 34 || $totale == 44 || $totale == 54 || $totale == 64 || $totale == 74 || $totale == 84 || $totale == 94 || $totale == 104; $frasi = file('frasi4.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 76).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 5 || $totale == 15 || $totale == 25 || $totale == 35 || $totale == 45 || $totale == 55 || $totale == 65 || $totale == 75 || $totale == 85 || $totale == 95 || $totale == 105; $frasi = file('txt/frasi5.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 95).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 6 || $totale == 16 || $totale == 26 || $totale == 36 || $totale == 46 || $totale == 56 || $totale == 66 || $totale == 76 || $totale == 86 || $totale == 96 || $totale == 106; $frasi = file('txt/frasi6.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 114).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 7 || $totale == 17 || $totale == 27 || $totale == 37 || $totale == 47 || $totale == 57 || $totale == 67 || $totale == 77 || $totale == 87 || $totale == 97 || $totale == 107; $frasi = file('txt/frasi7.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 133).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 8 || $totale == 18 || $totale == 28 || $totale == 38 || $totale == 48 || $totale == 58 || $totale == 68 || $totale == 78 || $totale == 88 || $totale == 98 || $totale == 108; $frasi = file('txt/frasi8.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 152).'">' . $frasi[$indice_random] . '</a>'; break; case $totale == 9 || $totale == 19 || $totale == 29 || $totale == 39 || $totale == 49 || $totale == 59 || $totale == 69 || $totale == 79 || $totale == 89 || $totale == 99 || $totale == 109 || $totale == $totale >= 110; $frasi = file('txt/frasi9.txt', FILE_IGNORE_NEW_LINES); $indice_random = array_rand($frasi); echo '<a href="condividi.php?id_frase='.($indice_random + 171).'">' . $frasi[$indice_random] . '</a>'; break; } } else { $frasi = file('txt/frasi.txt', FILE_IGNORE_NEW_LINES); $indice_random = $_GET['id_frase']; echo $frasi[$indice_random]; }?>
Scusate l'immane lunghezza, spero che qualche buon anima si prenda la briga di legger tutto
Grazie mille e buona serata 
Siccome mi accorgo ora che i codici vengono fuori incasinati, guardate qui: http://forum.it.altervista.org/php-m...ml#post1102376