ciao a tutti!
dopo molta ricerca, ho trovato il codice in php che permette di creare un guestbook senza aver bisogno di un database di supporto: si inserisce un nome, il messaggio e confermando il messaggio si salva nella stessa pagina.
volevo però capire come funziona il codice, qualcuno potrebbe gentilmente commentarlo?
grazie a tutti! buona serata!
codice:
<?PHP ob_start(); header("Cache-Control: No-Cache"); if (!is_file("philip_data")){ $dbc = sqlite_open("philip_data"); $query = "CREATE TABLE guestbook (inputId PRIMARY KEY, inputText TEXT NOT NULL);"; sqlite_query($dbc,$query); header("Location: {$_SERVER['PHP_SELF']}"); } else { $dbc = sqlite_open("philip_data"); if ($_POST['message']){ $tid = date("H:i:s d/m-Y"); $_POST['message'] = stripslashes(htmlspecialchars($_POST['message'])); $_POST['name'] = stripslashes(htmlspecialchars($_POST['name'])); $mess = "Postet av: {$_POST['name']}
{$_POST['message']}
Postet: $tid<hr/>"; $query = "INSERT INTO guestbook (inputText) VALUES ('$mess');"; sqlite_query($dbc,$query); header("Location: {$_SERVER['PHP_SELF']}"); } $query = "SELECT inputText FROM guestbook ORDER BY inputId DESC;"; $array = sqlite_single_query($dbc,$query); if(count($array)>15){ $extrapages = floor(count($array)/15); $extrapages++; if (count($array)%15 == 0){ $extrapages--; } if($_GET['page']){ $num = $_GET['page'] * 15; for($i=$num;$i<count($array);$i++){ $extra[] = array_pop($array); } for($i=0;$i<$num-15;$i++){ $extra[] = array_shift($array); } } else { for($i=15;$i<count($array);$i++){ $extra[] = array_pop($array); } } } echo "<table border=\"0\" cellpadding=\"10\" cols=\"50\"><tr><td><form action=\"{$_SERVER['PHP_SELF']}\" method=\"POST\">Socio: <input type=\"text\" name=\"name\" />
Scrivi il tuo messaggio:
<textarea cols=\"30\" rows=\"10\" name=\"message\"></textarea>
<input type=\"submit\" value=\"Firma.\"/></form></td></tr>"; if($array && is_array($array)){ foreach ($array as $input){ echo "<tr><td width=\"20\">$input</td></tr>\n"; } } elseif ($array){ echo "<tr><td width=\"20\">$array</td></tr>"; } else { echo "<td><tr><h4>Ecco tutti i messaggi dei soci!</h4></td></tr>"; } echo "</table>"; if ($extrapages != 0){ echo extrapages($extrapages); } } function extrapages($num){ $to = "<table borders=\"0\" cellpadding=\"10\"><tr><td>"; for($i=0;$i<$num;$i++){ $top = $i+1; $to .= "<a href=\"?page=$top\">$top</a> "; } $to .= "</td></tr></table>"; return $to; } ?>