Questo è il codice di administrator.php
Codice PHP:
<?php
include("protezione.php");
#specifichiamo il percorso del nostro file txt
$percorso = file("data.txt");
$count = 0;
?>
<form name="form1" method="post" action="modulo.php" >
<table>
<?
while(list(,$value) = each($percorso))
{
list($descrizione, $prezzo) = split("[:]", $value);
$params["descrizione"] = trim($descrizione);
$params["prezzo"] = trim($prezzo);
?>
<tr>
<td width="77%">
<textarea name="desc<?= $count ?>" cols="50" rows="4"><?= $params["descrizione"] ?></textarea></td>
<td width="100" valign="top">
<input name="prezzo<?= $count ?>" value="<?= $params["prezzo"] ?>">
</td>
</tr>
<tr>
<td colspan="2"><hr width="100%" size="1" noshade></td>
</tr>
<?
$count++;
}
?>
<tr>
<td>
<div align="left">
<input type="submit" name="Submit" value="Invia">
</div></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
Questo invece il codice di protezione.php
Codice PHP:
<?php
session_start();
$admin = $_SESSION['sessione'];
if ($admin != 1){
header("Location: change.php");
exit("Area riservata");
}
else
?>
Questo il codice di modulo.php
Codice PHP:
<?php
$desc0 = str_replace("\n", " ", $desc0);
$stringa0 = $desc0 . ":" . $prezzo0 . "\n";
$desc1 = str_replace("\n", " ", $desc1);
$stringa1 = $desc1 . ":" . $prezzo1 . "\n";
$desc2 = str_replace("\n", " ", $desc2);
$stringa2 = $desc2 . ":" . $prezzo2 . "\n";
$file = fopen("data.txt", "w+");
fwrite($file, $stringa0);
fwrite($file, $stringa1);
fwrite($file, $stringa2);
fclose($file);
header("Location: administrator.php");
?>
Questo il codice di change.php
Codice PHP:
<?
if ( $pass != "paperino" and $login != "pippo") {
?>
<form name="form1" method="post" action="change.php">
Nome
<input name="login" type="text" id="login">
Password
<input name="pass" type="password" id="pass">
<input type="submit" name="Submit" value="Invia">
</p>
</form>
<?
}
else {
session_start();
$admin = 1;
$_SESSION['sessione'] = $admin;
echo "login effetuato";
header("Location: administrator.php");
}
?>
Grazie infinite