... Questo invece è il codice della pagina:
Codice PHP:
// impostazioni variabili
$og_html=array("nick","oggetto");
$fnome="./messaggi.txt";
// funzione controllo
function controllo() {
global $og_html, $_REQUEST;
foreach($og_html as $val) {
if(empty($_REQUEST[$val])) return false;
};
return true;
}
// controllo dati ricevuti
if(controllo()) {
// modifica dati
$nick=substr($_REQUEST["nick"],0,10);
$oggetto=substr($_REQUEST["oggetto"],0,60);
$nick=htmlspecialchars($nick);
$oggetto=htmlspecialchars($oggetto);
// apertura file
$file=file($fnome);
for($x=1; $x<count($file); $x++) $file_tmp[]=$file[$x];
$file_tmp[]="\n$nick: $oggetto";
$file=fopen($fnome,"w+");
fwrite($file,implode("",$file_tmp));
fclose($file);
};
// lettura file
$file=file($fnome);
// formattazione
unset($tmp_file);
for($x=0; $x<count($file); $x++) {
$file[$x]=addslashes(trim($file[$x],"\n"));
};
for($x=count($file)-1; $x>=0; $x--) $tmp_file[]=$file[$x];
// variabile da passare allo script
$cont_file=implode(" - ",$tmp_file);
?>
<html>
<head>
<title>Messaggi scorrevoli</title>
<style type="text/css">
<!--
a {
color:blue;
text-decoration:underline
}
a:hover {
color:red;
text-decoration:underline overline
}
body {
font:normal 1pc arial;
color:black
}
table#tab_cont td {
border:#000000 1px solid
}
input {
border:#000000 1px solid
}
-->
</style>
</head>
<body>
<table style="border:#000000 1px solid; width: 349px; height: 291px;">
<tr><td>
<div id="frm">
<form method="post" action="<?php print($_SERVER["PHP_SELF"]); ?>" onsubmit="return valida(this);" style="padding:0px; margin:0px">
<table style="width: 338px; height: 188px">
<tr><td>Nick:</td><td><input type="text" name="nick" style="width: 194px"></td></tr>
<tr><td>Oggetto:</td><td>
<textarea name="TextArea1" style="height: 89px; width: 249px"></textarea></td></tr>
<tr><td colspan="2" align="center"><input type="reset" value="Resetta"><input type="submit" value="Invia"></td></tr>
</table>
</form>
</div>
</td></tr>
<tr>
</tr>
<td>
</td>
<script type="text/javascript">
<!--
var tempo=100;
var scroll=5;
var timer=null;
var timer_indietro=null;
var timer_avanti=null;
var scroll_vel=scroll+10;
// funzione valida
function valida(qst) {
var reg=new RegExp("^[ ]*$");
var chi=null;
try {
if(reg.test(qst.nick.value)) {
chi="nick";
throw "Non hai inserito il nick...";
};
if(reg.test(qst.oggetto.value)) {
chi="oggetto";
throw "Non hai inserito l'oggetto...";
};
}
catch(mes) {
window.alert(mes);
qst.elements[chi].focus();
return false;
};
return true;
};
</script>